home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 240 (DVD) / Issue 240 - February 2008 - DPCS0208DVD.ISO / BO Expert tools / AutoHotKey / Source / AutoHotkey104702_source.exe / source / lib_pcre / pcre / pcre_exec.c < prev    next >
Encoding:
C/C++ Source or Header  |  2007-01-11  |  124.2 KB  |  4,211 lines

  1. /*************************************************
  2. *      Perl-Compatible Regular Expressions       *
  3. *************************************************/
  4.  
  5. /* PCRE is a library of functions to support regular expressions whose syntax
  6. and semantics are as close as possible to those of the Perl 5 language.
  7.  
  8.                        Written by Philip Hazel
  9.            Copyright (c) 1997-2006 University of Cambridge
  10.  
  11. -----------------------------------------------------------------------------
  12. Redistribution and use in source and binary forms, with or without
  13. modification, are permitted provided that the following conditions are met:
  14.  
  15.     * Redistributions of source code must retain the above copyright notice,
  16.       this list of conditions and the following disclaimer.
  17.  
  18.     * Redistributions in binary form must reproduce the above copyright
  19.       notice, this list of conditions and the following disclaimer in the
  20.       documentation and/or other materials provided with the distribution.
  21.  
  22.     * Neither the name of the University of Cambridge nor the names of its
  23.       contributors may be used to endorse or promote products derived from
  24.       this software without specific prior written permission.
  25.  
  26. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  27. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  28. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  29. ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  30. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  31. CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  32. SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  33. INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  34. CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  35. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  36. POSSIBILITY OF SUCH DAMAGE.
  37. -----------------------------------------------------------------------------
  38. */
  39.  
  40.  
  41. /* This module contains pcre_exec(), the externally visible function that does
  42. pattern matching using an NFA algorithm, trying to mimic Perl as closely as
  43. possible. There are also some static supporting functions. */
  44.  
  45. #define NLBLOCK md             /* Block containing newline information */
  46. #define PSSTART start_subject  /* Field containing processed string start */
  47. #define PSEND   end_subject    /* Field containing processed string end */
  48.  
  49. #include "pcre_internal.h"
  50.  
  51. /* The chain of eptrblocks for tail recursions uses memory in stack workspace,
  52. obtained at top level, the size of which is defined by EPTR_WORK_SIZE. */
  53.  
  54. #define EPTR_WORK_SIZE (1000)
  55.  
  56. /* Flag bits for the match() function */
  57.  
  58. #define match_condassert     0x01  /* Called to check a condition assertion */
  59. #define match_cbegroup       0x02  /* Could-be-empty unlimited repeat group */
  60. #define match_tail_recursed  0x04  /* Tail recursive call */
  61.  
  62. /* Non-error returns from the match() function. Error returns are externally
  63. defined PCRE_ERROR_xxx codes, which are all negative. */
  64.  
  65. #define MATCH_MATCH        1
  66. #define MATCH_NOMATCH      0
  67.  
  68. /* Maximum number of ints of offset to save on the stack for recursive calls.
  69. If the offset vector is bigger, malloc is used. This should be a multiple of 3,
  70. because the offset vector is always a multiple of 3 long. */
  71.  
  72. #define REC_STACK_SAVE_MAX 30
  73.  
  74. /* Min and max values for the common repeats; for the maxima, 0 => infinity */
  75.  
  76. static const char rep_min[] = { 0, 0, 1, 1, 0, 0 };
  77. static const char rep_max[] = { 0, 0, 0, 0, 1, 1 };
  78.  
  79.  
  80.  
  81. #ifdef DEBUG
  82. /*************************************************
  83. *        Debugging function to print chars       *
  84. *************************************************/
  85.  
  86. /* Print a sequence of chars in printable format, stopping at the end of the
  87. subject if the requested.
  88.  
  89. Arguments:
  90.   p           points to characters
  91.   length      number to print
  92.   is_subject  TRUE if printing from within md->start_subject
  93.   md          pointer to matching data block, if is_subject is TRUE
  94.  
  95. Returns:     nothing
  96. */
  97.  
  98. static void
  99. pchars(const uschar *p, int length, BOOL is_subject, match_data *md)
  100. {
  101. unsigned int c;
  102. if (is_subject && length > md->end_subject - p) length = md->end_subject - p;
  103. while (length-- > 0)
  104.   if (isprint(c = *(p++))) printf("%c", c); else printf("\\x%02x", c);
  105. }
  106. #endif
  107.  
  108.  
  109.  
  110. /*************************************************
  111. *          Match a back-reference                *
  112. *************************************************/
  113.  
  114. /* If a back reference hasn't been set, the length that is passed is greater
  115. than the number of characters left in the string, so the match fails.
  116.  
  117. Arguments:
  118.   offset      index into the offset vector
  119.   eptr        points into the subject
  120.   length      length to be matched
  121.   md          points to match data block
  122.   ims         the ims flags
  123.  
  124. Returns:      TRUE if matched
  125. */
  126.  
  127. static BOOL
  128. match_ref(int offset, register USPTR eptr, int length, match_data *md,
  129.   unsigned long int ims)
  130. {
  131. USPTR p = md->start_subject + md->offset_vector[offset];
  132.  
  133. #ifdef DEBUG
  134. if (eptr >= md->end_subject)
  135.   printf("matching subject <null>");
  136. else
  137.   {
  138.   printf("matching subject ");
  139.   pchars(eptr, length, TRUE, md);
  140.   }
  141. printf(" against backref ");
  142. pchars(p, length, FALSE, md);
  143. printf("\n");
  144. #endif
  145.  
  146. /* Always fail if not enough characters left */
  147.  
  148. if (length > md->end_subject - eptr) return FALSE;
  149.  
  150. /* Separate the caselesss case for speed */
  151.  
  152. if ((ims & PCRE_CASELESS) != 0)
  153.   {
  154.   while (length-- > 0)
  155.     if (md->lcc[*p++] != md->lcc[*eptr++]) return FALSE;
  156.   }
  157. else
  158.   { while (length-- > 0) if (*p++ != *eptr++) return FALSE; }
  159.  
  160. return TRUE;
  161. }
  162.  
  163.  
  164.  
  165. /***************************************************************************
  166. ****************************************************************************
  167.                    RECURSION IN THE match() FUNCTION
  168.  
  169. The match() function is highly recursive, though not every recursive call
  170. increases the recursive depth. Nevertheless, some regular expressions can cause
  171. it to recurse to a great depth. I was writing for Unix, so I just let it call
  172. itself recursively. This uses the stack for saving everything that has to be
  173. saved for a recursive call. On Unix, the stack can be large, and this works
  174. fine.
  175.  
  176. It turns out that on some non-Unix-like systems there are problems with
  177. programs that use a lot of stack. (This despite the fact that every last chip
  178. has oodles of memory these days, and techniques for extending the stack have
  179. been known for decades.) So....
  180.  
  181. There is a fudge, triggered by defining NO_RECURSE, which avoids recursive
  182. calls by keeping local variables that need to be preserved in blocks of memory
  183. obtained from malloc() instead instead of on the stack. Macros are used to
  184. achieve this so that the actual code doesn't look very different to what it
  185. always used to.
  186. ****************************************************************************
  187. ***************************************************************************/
  188.  
  189.  
  190. /* These versions of the macros use the stack, as normal. There are debugging
  191. versions and production versions. */
  192.  
  193. #ifndef NO_RECURSE
  194. #define REGISTER register
  195. #ifdef DEBUG
  196. #define RMATCH(rx,ra,rb,rc,rd,re,rf,rg) \
  197.   { \
  198.   printf("match() called in line %d\n", __LINE__); \
  199.   rx = match(ra,rb,rc,rd,re,rf,rg,rdepth+1); \
  200.   printf("to line %d\n", __LINE__); \
  201.   }
  202. #define RRETURN(ra) \
  203.   { \
  204.   printf("match() returned %d from line %d ", ra, __LINE__); \
  205.   return ra; \
  206.   }
  207. #else
  208. #define RMATCH(rx,ra,rb,rc,rd,re,rf,rg) \
  209.   rx = match(ra,rb,rc,rd,re,rf,rg,rdepth+1)
  210. #define RRETURN(ra) return ra
  211. #endif
  212.  
  213. #else
  214.  
  215.  
  216. /* These versions of the macros manage a private stack on the heap. Note
  217. that the rd argument of RMATCH isn't actually used. It's the md argument of
  218. match(), which never changes. */
  219.  
  220. #define REGISTER
  221.  
  222. #define RMATCH(rx,ra,rb,rc,rd,re,rf,rg)\
  223.   {\
  224.   heapframe *newframe = (pcre_stack_malloc)(sizeof(heapframe));\
  225.   if (setjmp(frame->Xwhere) == 0)\
  226.     {\
  227.     newframe->Xeptr = ra;\
  228.     newframe->Xecode = rb;\
  229.     newframe->Xoffset_top = rc;\
  230.     newframe->Xims = re;\
  231.     newframe->Xeptrb = rf;\
  232.     newframe->Xflags = rg;\
  233.     newframe->Xrdepth = frame->Xrdepth + 1;\
  234.     newframe->Xprevframe = frame;\
  235.     frame = newframe;\
  236.     DPRINTF(("restarting from line %d\n", __LINE__));\
  237.     goto HEAP_RECURSE;\
  238.     }\
  239.   else\
  240.     {\
  241.     DPRINTF(("longjumped back to line %d\n", __LINE__));\
  242.     frame = md->thisframe;\
  243.     rx = frame->Xresult;\
  244.     }\
  245.   }
  246.  
  247. #define RRETURN(ra)\
  248.   {\
  249.   heapframe *newframe = frame;\
  250.   frame = newframe->Xprevframe;\
  251.   (pcre_stack_free)(newframe);\
  252.   if (frame != NULL)\
  253.     {\
  254.     frame->Xresult = ra;\
  255.     md->thisframe = frame;\
  256.     longjmp(frame->Xwhere, 1);\
  257.     }\
  258.   return ra;\
  259.   }
  260.  
  261.  
  262. /* Structure for remembering the local variables in a private frame */
  263.  
  264. typedef struct heapframe {
  265.   struct heapframe *Xprevframe;
  266.  
  267.   /* Function arguments that may change */
  268.  
  269.   const uschar *Xeptr;
  270.   const uschar *Xecode;
  271.   int Xoffset_top;
  272.   long int Xims;
  273.   eptrblock *Xeptrb;
  274.   int Xflags;
  275.   unsigned int Xrdepth;
  276.  
  277.   /* Function local variables */
  278.  
  279.   const uschar *Xcallpat;
  280.   const uschar *Xcharptr;
  281.   const uschar *Xdata;
  282.   const uschar *Xnext;
  283.   const uschar *Xpp;
  284.   const uschar *Xprev;
  285.   const uschar *Xsaved_eptr;
  286.  
  287.   recursion_info Xnew_recursive;
  288.  
  289.   BOOL Xcur_is_word;
  290.   BOOL Xcondition;
  291.   BOOL Xprev_is_word;
  292.  
  293.   unsigned long int Xoriginal_ims;
  294.  
  295. #ifdef SUPPORT_UCP
  296.   int Xprop_type;
  297.   int Xprop_value;
  298.   int Xprop_fail_result;
  299.   int Xprop_category;
  300.   int Xprop_chartype;
  301.   int Xprop_script;
  302. #endif
  303.  
  304.   int Xctype;
  305.   unsigned int Xfc;
  306.   int Xfi;
  307.   int Xlength;
  308.   int Xmax;
  309.   int Xmin;
  310.   int Xnumber;
  311.   int Xoffset;
  312.   int Xop;
  313.   int Xsave_capture_last;
  314.   int Xsave_offset1, Xsave_offset2, Xsave_offset3;
  315.   int Xstacksave[REC_STACK_SAVE_MAX];
  316.  
  317.   eptrblock Xnewptrb;
  318.  
  319.   /* Place to pass back result, and where to jump back to */
  320.  
  321.   int  Xresult;
  322.   jmp_buf Xwhere;
  323.  
  324. } heapframe;
  325.  
  326. #endif
  327.  
  328.  
  329. /***************************************************************************
  330. ***************************************************************************/
  331.  
  332.  
  333.  
  334. /*************************************************
  335. *         Match from current position            *
  336. *************************************************/
  337.  
  338. /* This function is called recursively in many circumstances. Whenever it
  339. returns a negative (error) response, the outer incarnation must also return the
  340. same response.
  341.  
  342. Performance note: It might be tempting to extract commonly used fields from the
  343. md structure (e.g. utf8, end_subject) into individual variables to improve
  344. performance. Tests using gcc on a SPARC disproved this; in the first case, it
  345. made performance worse.
  346.  
  347. Arguments:
  348.    eptr        pointer to current character in subject
  349.    ecode       pointer to current position in compiled code
  350.    offset_top  current top pointer
  351.    md          pointer to "static" info for the match
  352.    ims         current /i, /m, and /s options
  353.    eptrb       pointer to chain of blocks containing eptr at start of
  354.                  brackets - for testing for empty matches
  355.    flags       can contain
  356.                  match_condassert - this is an assertion condition
  357.                  match_cbegroup - this is the start of an unlimited repeat
  358.                    group that can match an empty string
  359.                  match_tail_recursed - this is a tail_recursed group
  360.    rdepth      the recursion depth
  361.  
  362. Returns:       MATCH_MATCH if matched            )  these values are >= 0
  363.                MATCH_NOMATCH if failed to match  )
  364.                a negative PCRE_ERROR_xxx value if aborted by an error condition
  365.                  (e.g. stopped by repeated call or recursion limit)
  366. */
  367.  
  368. static int
  369. match(REGISTER USPTR eptr, REGISTER const uschar *ecode,
  370.   int offset_top, match_data *md, unsigned long int ims, eptrblock *eptrb,
  371.   int flags, unsigned int rdepth)
  372. {
  373. /* These variables do not need to be preserved over recursion in this function,
  374. so they can be ordinary variables in all cases. Mark some of them with
  375. "register" because they are used a lot in loops. */
  376.  
  377. register int  rrc;         /* Returns from recursive calls */
  378. register int  i;           /* Used for loops not involving calls to RMATCH() */
  379. register unsigned int c;   /* Character values not kept over RMATCH() calls */
  380. #ifdef SUPPORT_UTF8 /* AutoHotkey: This helps detected unintended usages of utf8. */
  381.     register BOOL utf8;        /* Local copy of UTF-8 flag for speed */
  382. #endif /* AutoHotkey. */
  383.  
  384. BOOL minimize, possessive; /* Quantifier options */
  385.  
  386. /* When recursion is not being used, all "local" variables that have to be
  387. preserved over calls to RMATCH() are part of a "frame" which is obtained from
  388. heap storage. Set up the top-level frame here; others are obtained from the
  389. heap whenever RMATCH() does a "recursion". See the macro definitions above. */
  390.  
  391. #ifdef NO_RECURSE
  392. heapframe *frame = (pcre_stack_malloc)(sizeof(heapframe));
  393. frame->Xprevframe = NULL;            /* Marks the top level */
  394.  
  395. /* Copy in the original argument variables */
  396.  
  397. frame->Xeptr = eptr;
  398. frame->Xecode = ecode;
  399. frame->Xoffset_top = offset_top;
  400. frame->Xims = ims;
  401. frame->Xeptrb = eptrb;
  402. frame->Xflags = flags;
  403. frame->Xrdepth = rdepth;
  404.  
  405. /* This is where control jumps back to to effect "recursion" */
  406.  
  407. HEAP_RECURSE:
  408.  
  409. /* Macros make the argument variables come from the current frame */
  410.  
  411. #define eptr               frame->Xeptr
  412. #define ecode              frame->Xecode
  413. #define offset_top         frame->Xoffset_top
  414. #define ims                frame->Xims
  415. #define eptrb              frame->Xeptrb
  416. #define flags              frame->Xflags
  417. #define rdepth             frame->Xrdepth
  418.  
  419. /* Ditto for the local variables */
  420.  
  421. #ifdef SUPPORT_UTF8
  422. #define charptr            frame->Xcharptr
  423. #endif
  424. #define callpat            frame->Xcallpat
  425. #define data               frame->Xdata
  426. #define next               frame->Xnext
  427. #define pp                 frame->Xpp
  428. #define prev               frame->Xprev
  429. #define saved_eptr         frame->Xsaved_eptr
  430.  
  431. #define new_recursive      frame->Xnew_recursive
  432.  
  433. #define cur_is_word        frame->Xcur_is_word
  434. #define condition          frame->Xcondition
  435. #define prev_is_word       frame->Xprev_is_word
  436.  
  437. #define original_ims       frame->Xoriginal_ims
  438.  
  439. #ifdef SUPPORT_UCP
  440. #define prop_type          frame->Xprop_type
  441. #define prop_value         frame->Xprop_value
  442. #define prop_fail_result   frame->Xprop_fail_result
  443. #define prop_category      frame->Xprop_category
  444. #define prop_chartype      frame->Xprop_chartype
  445. #define prop_script        frame->Xprop_script
  446. #endif
  447.  
  448. #define ctype              frame->Xctype
  449. #define fc                 frame->Xfc
  450. #define fi                 frame->Xfi
  451. #define length             frame->Xlength
  452. #define max                frame->Xmax
  453. #define min                frame->Xmin
  454. #define number             frame->Xnumber
  455. #define offset             frame->Xoffset
  456. #define op                 frame->Xop
  457. #define save_capture_last  frame->Xsave_capture_last
  458. #define save_offset1       frame->Xsave_offset1
  459. #define save_offset2       frame->Xsave_offset2
  460. #define save_offset3       frame->Xsave_offset3
  461. #define stacksave          frame->Xstacksave
  462.  
  463. #define newptrb            frame->Xnewptrb
  464.  
  465. /* When recursion is being used, local variables are allocated on the stack and
  466. get preserved during recursion in the normal way. In this environment, fi and
  467. i, and fc and c, can be the same variables. */
  468.  
  469. #else         /* NO_RECURSE not defined */
  470. #define fi i
  471. #define fc c
  472.  
  473.  
  474. #ifdef SUPPORT_UTF8                /* Many of these variables are used only  */
  475. const uschar *charptr;             /* in small blocks of the code. My normal */
  476. #endif                             /* style of coding would have declared    */
  477. const uschar *callpat;             /* them within each of those blocks.      */
  478. const uschar *data;                /* However, in order to accommodate the   */
  479. const uschar *next;                /* version of this code that uses an      */
  480. USPTR         pp;                  /* external "stack" implemented on the    */
  481. const uschar *prev;                /* heap, it is easier to declare them all */
  482. USPTR         saved_eptr;          /* here, so the declarations can be cut   */
  483.                                    /* out in a block. The only declarations  */
  484. recursion_info new_recursive;      /* within blocks below are for variables  */
  485.                                    /* that do not have to be preserved over  */
  486. BOOL cur_is_word;                  /* a recursive call to RMATCH().          */
  487. BOOL condition;
  488. BOOL prev_is_word;
  489.  
  490. unsigned long int original_ims;
  491.  
  492. #ifdef SUPPORT_UCP
  493. int prop_type;
  494. int prop_value;
  495. int prop_fail_result;
  496. int prop_category;
  497. int prop_chartype;
  498. int prop_script;
  499. #endif
  500.  
  501. int ctype;
  502. int length;
  503. int max;
  504. int min;
  505. int number;
  506. int offset;
  507. int op;
  508. int save_capture_last;
  509. int save_offset1, save_offset2, save_offset3;
  510. int stacksave[REC_STACK_SAVE_MAX];
  511.  
  512. eptrblock newptrb;
  513. #endif     /* NO_RECURSE */
  514.  
  515. /* These statements are here to stop the compiler complaining about unitialized
  516. variables. */
  517.  
  518. #ifdef SUPPORT_UCP
  519. prop_value = 0;
  520. prop_fail_result = 0;
  521. #endif
  522.  
  523.  
  524. /* This label is used for tail recursion, which is used in a few cases even
  525. when NO_RECURSE is not defined, in order to reduce the amount of stack that is
  526. used. Thanks to Ian Taylor for noticing this possibility and sending the
  527. original patch. */
  528.  
  529. TAIL_RECURSE:
  530.  
  531. /* OK, now we can get on with the real code of the function. Recursive calls
  532. are specified by the macro RMATCH and RRETURN is used to return. When
  533. NO_RECURSE is *not* defined, these just turn into a recursive call to match()
  534. and a "return", respectively (possibly with some debugging if DEBUG is
  535. defined). However, RMATCH isn't like a function call because it's quite a
  536. complicated macro. It has to be used in one particular way. This shouldn't,
  537. however, impact performance when true recursion is being used. */
  538.  
  539. /* First check that we haven't called match() too many times, or that we
  540. haven't exceeded the recursive call limit. */
  541.  
  542. if (md->match_call_count++ >= md->match_limit) RRETURN(PCRE_ERROR_MATCHLIMIT);
  543. if (rdepth >= md->match_limit_recursion) RRETURN(PCRE_ERROR_RECURSIONLIMIT);
  544.  
  545. original_ims = ims;    /* Save for resetting on ')' */
  546.  
  547. #ifdef SUPPORT_UTF8
  548. utf8 = md->utf8;       /* Local copy of the flag */
  549. /* AutoHotkey: Commented out to help detect unintended usages of utf8:
  550. #else
  551. utf8 = FALSE; */
  552. #endif
  553.  
  554. /* At the start of a group with an unlimited repeat that may match an empty
  555. string, the match_cbegroup flag is set. When this is the case, add the current
  556. subject pointer to the chain of such remembered pointers, to be checked when we
  557. hit the closing ket, in order to break infinite loops that match no characters.
  558. When match() is called in other circumstances, don't add to the chain. If this
  559. is a tail recursion, use a block from the workspace, as the one on the stack is
  560. already used. */
  561.  
  562. if ((flags & match_cbegroup) != 0)
  563.   {
  564.   eptrblock *p;
  565.   if ((flags & match_tail_recursed) != 0)
  566.     {
  567.     if (md->eptrn >= EPTR_WORK_SIZE) RRETURN(PCRE_ERROR_NULLWSLIMIT);
  568.     p = md->eptrchain + md->eptrn++;
  569.     }
  570.   else p = &newptrb;
  571.   p->epb_saved_eptr = eptr;
  572.   p->epb_prev = eptrb;
  573.   eptrb = p;
  574.   }
  575.  
  576. /* Now start processing the opcodes. */
  577.  
  578. for (;;)
  579.   {
  580.   minimize = possessive = FALSE;
  581.   op = *ecode;
  582.  
  583.   /* For partial matching, remember if we ever hit the end of the subject after
  584.   matching at least one subject character. */
  585.  
  586.   if (md->partial &&
  587.       eptr >= md->end_subject &&
  588.       eptr > md->start_match)
  589.     md->hitend = TRUE;
  590.  
  591.   switch(op)
  592.     {
  593.     /* Handle a capturing bracket. If there is space in the offset vector, save
  594.     the current subject position in the working slot at the top of the vector.
  595.     We mustn't change the current values of the data slot, because they may be
  596.     set from a previous iteration of this group, and be referred to by a
  597.     reference inside the group.
  598.  
  599.     If the bracket fails to match, we need to restore this value and also the
  600.     values of the final offsets, in case they were set by a previous iteration
  601.     of the same bracket.
  602.  
  603.     If there isn't enough space in the offset vector, treat this as if it were
  604.     a non-capturing bracket. Don't worry about setting the flag for the error
  605.     case here; that is handled in the code for KET. */
  606.  
  607.     case OP_CBRA:
  608.     case OP_SCBRA:
  609.     number = GET2(ecode, 1+LINK_SIZE);
  610.     offset = number << 1;
  611.  
  612. #ifdef DEBUG
  613.     printf("start bracket %d\n", number);
  614.     printf("subject=");
  615.     pchars(eptr, 16, TRUE, md);
  616.     printf("\n");
  617. #endif
  618.  
  619.     if (offset < md->offset_max)
  620.       {
  621.       save_offset1 = md->offset_vector[offset];
  622.       save_offset2 = md->offset_vector[offset+1];
  623.       save_offset3 = md->offset_vector[md->offset_end - number];
  624.       save_capture_last = md->capture_last;
  625.  
  626.       DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3));
  627.       md->offset_vector[md->offset_end - number] = eptr - md->start_subject;
  628.  
  629.       flags = (op == OP_SCBRA)? match_cbegroup : 0;
  630.       do
  631.         {
  632.         RMATCH(rrc, eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
  633.           ims, eptrb, flags);
  634.         if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  635.         md->capture_last = save_capture_last;
  636.         ecode += GET(ecode, 1);
  637.         }
  638.       while (*ecode == OP_ALT);
  639.  
  640.       DPRINTF(("bracket %d failed\n", number));
  641.  
  642.       md->offset_vector[offset] = save_offset1;
  643.       md->offset_vector[offset+1] = save_offset2;
  644.       md->offset_vector[md->offset_end - number] = save_offset3;
  645.  
  646.       RRETURN(MATCH_NOMATCH);
  647.       }
  648.  
  649.     /* Insufficient room for saving captured contents. Treat as a non-capturing
  650.     bracket. */
  651.  
  652.     DPRINTF(("insufficient capture room: treat as non-capturing\n"));
  653.  
  654.     /* Non-capturing bracket. Loop for all the alternatives. When we get to the
  655.     final alternative within the brackets, we would return the result of a
  656.     recursive call to match() whatever happened. We can reduce stack usage by
  657.     turning this into a tail recursion. */
  658.  
  659.     case OP_BRA:
  660.     case OP_SBRA:
  661.     DPRINTF(("start non-capturing bracket\n"));
  662.     flags = (op >= OP_SBRA)? match_cbegroup : 0;
  663.     for (;;)
  664.       {
  665.       if (ecode[GET(ecode, 1)] != OP_ALT)
  666.         {
  667.         ecode += _pcre_OP_lengths[*ecode];
  668.         flags |= match_tail_recursed;
  669.         DPRINTF(("bracket 0 tail recursion\n"));
  670.         goto TAIL_RECURSE;
  671.         }
  672.  
  673.       /* For non-final alternatives, continue the loop for a NOMATCH result;
  674.       otherwise return. */
  675.  
  676.       RMATCH(rrc, eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims,
  677.         eptrb, flags);
  678.       if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  679.       ecode += GET(ecode, 1);
  680.       }
  681.     /* Control never reaches here. */
  682.  
  683.     /* Conditional group: compilation checked that there are no more than
  684.     two branches. If the condition is false, skipping the first branch takes us
  685.     past the end if there is only one branch, but that's OK because that is
  686.     exactly what going to the ket would do. As there is only one branch to be
  687.     obeyed, we can use tail recursion to avoid using another stack frame. */
  688.  
  689.     case OP_COND:
  690.     case OP_SCOND:
  691.     if (ecode[LINK_SIZE+1] == OP_RREF)         /* Recursion test */
  692.       {
  693.       offset = GET2(ecode, LINK_SIZE + 2);     /* Recursion group number*/
  694.       condition = md->recursive != NULL &&
  695.         (offset == RREF_ANY || offset == md->recursive->group_num);
  696.       ecode += condition? 3 : GET(ecode, 1);
  697.       }
  698.  
  699.     else if (ecode[LINK_SIZE+1] == OP_CREF)    /* Group used test */
  700.       {
  701.       offset = GET2(ecode, LINK_SIZE+2) << 1;  /* Doubled ref number */
  702.       condition = offset < offset_top && md->offset_vector[offset] >= 0;
  703.       ecode += condition? 3 : GET(ecode, 1);
  704.       }
  705.  
  706.     else if (ecode[LINK_SIZE+1] == OP_DEF)     /* DEFINE - always false */
  707.       {
  708.       condition = FALSE;
  709.       ecode += GET(ecode, 1);
  710.       }
  711.  
  712.     /* The condition is an assertion. Call match() to evaluate it - setting
  713.     the final argument match_condassert causes it to stop at the end of an
  714.     assertion. */
  715.  
  716.     else
  717.       {
  718.       RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL,
  719.           match_condassert);
  720.       if (rrc == MATCH_MATCH)
  721.         {
  722.         condition = TRUE;
  723.         ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE + 2);
  724.         while (*ecode == OP_ALT) ecode += GET(ecode, 1);
  725.         }
  726.       else if (rrc != MATCH_NOMATCH)
  727.         {
  728.         RRETURN(rrc);         /* Need braces because of following else */
  729.         }
  730.       else
  731.         {
  732.         condition = FALSE;
  733.         ecode += GET(ecode, 1);
  734.         }
  735.       }
  736.  
  737.     /* We are now at the branch that is to be obeyed. As there is only one,
  738.     we can use tail recursion to avoid using another stack frame. If the second
  739.     alternative doesn't exist, we can just plough on. */
  740.  
  741.     if (condition || *ecode == OP_ALT)
  742.       {
  743.       ecode += 1 + LINK_SIZE;
  744.       flags = match_tail_recursed | ((op == OP_SCOND)? match_cbegroup : 0);
  745.       goto TAIL_RECURSE;
  746.       }
  747.     else
  748.       {
  749.       ecode += 1 + LINK_SIZE;
  750.       }
  751.     break;
  752.  
  753.  
  754.     /* End of the pattern. If we are in a top-level recursion, we should
  755.     restore the offsets appropriately and continue from after the call. */
  756.  
  757.     case OP_END:
  758.     if (md->recursive != NULL && md->recursive->group_num == 0)
  759.       {
  760.       recursion_info *rec = md->recursive;
  761.       DPRINTF(("End of pattern in a (?0) recursion\n"));
  762.       md->recursive = rec->prevrec;
  763.       memmove(md->offset_vector, rec->offset_save,
  764.         rec->saved_max * sizeof(int));
  765.       md->start_match = rec->save_start;
  766.       ims = original_ims;
  767.       ecode = rec->after_call;
  768.       break;
  769.       }
  770.  
  771.     /* Otherwise, if PCRE_NOTEMPTY is set, fail if we have matched an empty
  772.     string - backtracking will then try other alternatives, if any. */
  773.  
  774.     if (md->notempty && eptr == md->start_match) RRETURN(MATCH_NOMATCH);
  775.     md->end_match_ptr = eptr;          /* Record where we ended */
  776.     md->end_offset_top = offset_top;   /* and how many extracts were taken */
  777.     RRETURN(MATCH_MATCH);
  778.  
  779.     /* Change option settings */
  780.  
  781.     case OP_OPT:
  782.     ims = ecode[1];
  783.     ecode += 2;
  784.     DPRINTF(("ims set to %02lx\n", ims));
  785.     break;
  786.  
  787.     /* Assertion brackets. Check the alternative branches in turn - the
  788.     matching won't pass the KET for an assertion. If any one branch matches,
  789.     the assertion is true. Lookbehind assertions have an OP_REVERSE item at the
  790.     start of each branch to move the current point backwards, so the code at
  791.     this level is identical to the lookahead case. */
  792.  
  793.     case OP_ASSERT:
  794.     case OP_ASSERTBACK:
  795.     do
  796.       {
  797.       RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0);
  798.       if (rrc == MATCH_MATCH) break;
  799.       if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  800.       ecode += GET(ecode, 1);
  801.       }
  802.     while (*ecode == OP_ALT);
  803.     if (*ecode == OP_KET) RRETURN(MATCH_NOMATCH);
  804.  
  805.     /* If checking an assertion for a condition, return MATCH_MATCH. */
  806.  
  807.     if ((flags & match_condassert) != 0) RRETURN(MATCH_MATCH);
  808.  
  809.     /* Continue from after the assertion, updating the offsets high water
  810.     mark, since extracts may have been taken during the assertion. */
  811.  
  812.     do ecode += GET(ecode,1); while (*ecode == OP_ALT);
  813.     ecode += 1 + LINK_SIZE;
  814.     offset_top = md->end_offset_top;
  815.     continue;
  816.  
  817.     /* Negative assertion: all branches must fail to match */
  818.  
  819.     case OP_ASSERT_NOT:
  820.     case OP_ASSERTBACK_NOT:
  821.     do
  822.       {
  823.       RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0);
  824.       if (rrc == MATCH_MATCH) RRETURN(MATCH_NOMATCH);
  825.       if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  826.       ecode += GET(ecode,1);
  827.       }
  828.     while (*ecode == OP_ALT);
  829.  
  830.     if ((flags & match_condassert) != 0) RRETURN(MATCH_MATCH);
  831.  
  832.     ecode += 1 + LINK_SIZE;
  833.     continue;
  834.  
  835.     /* Move the subject pointer back. This occurs only at the start of
  836.     each branch of a lookbehind assertion. If we are too close to the start to
  837.     move back, this match function fails. When working with UTF-8 we move
  838.     back a number of characters, not bytes. */
  839.  
  840.     case OP_REVERSE:
  841. #ifdef SUPPORT_UTF8
  842.     if (utf8)
  843.       {
  844.       i = GET(ecode, 1);
  845.       while (i-- > 0)
  846.         {
  847.         eptr--;
  848.         if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);
  849.         BACKCHAR(eptr)
  850.         }
  851.       }
  852.     else
  853. #endif
  854.  
  855.     /* No UTF-8 support, or not in UTF-8 mode: count is byte count */
  856.  
  857.       {
  858.       eptr -= GET(ecode, 1);
  859.       if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);
  860.       }
  861.  
  862.     /* Skip to next op code */
  863.  
  864.     ecode += 1 + LINK_SIZE;
  865.     break;
  866.  
  867.     /* The callout item calls an external function, if one is provided, passing
  868.     details of the match so far. This is mainly for debugging, though the
  869.     function is able to force a failure. */
  870.  
  871.     case OP_CALLOUT:
  872. #ifdef SUPPORT_CALLOUT  /* AutoHotkey: Omit the callout feature from the code until it's needed. */
  873.     if (pcre_callout != NULL)
  874.       {
  875.       pcre_callout_block cb;
  876.       cb.version          = 1;   /* Version 1 of the callout block */
  877.       cb.callout_number   = ecode[1];
  878.       cb.offset_vector    = md->offset_vector;
  879.       cb.subject          = (PCRE_SPTR)md->start_subject;
  880.       cb.subject_length   = md->end_subject - md->start_subject;
  881.       cb.start_match      = md->start_match - md->start_subject;
  882.       cb.current_position = eptr - md->start_subject;
  883.       cb.pattern_position = GET(ecode, 2);
  884.       cb.next_item_length = GET(ecode, 2 + LINK_SIZE);
  885.       cb.capture_top      = offset_top/2;
  886.       cb.capture_last     = md->capture_last;
  887.       cb.callout_data     = md->callout_data;
  888.       if ((rrc = (*pcre_callout)(&cb)) > 0) RRETURN(MATCH_NOMATCH);
  889.       if (rrc < 0) RRETURN(rrc);
  890.       }
  891. #endif /* AutoHotkey */
  892.     ecode += 2 + 2*LINK_SIZE;
  893.     break;
  894.  
  895.     /* Recursion either matches the current regex, or some subexpression. The
  896.     offset data is the offset to the starting bracket from the start of the
  897.     whole pattern. (This is so that it works from duplicated subpatterns.)
  898.  
  899.     If there are any capturing brackets started but not finished, we have to
  900.     save their starting points and reinstate them after the recursion. However,
  901.     we don't know how many such there are (offset_top records the completed
  902.     total) so we just have to save all the potential data. There may be up to
  903.     65535 such values, which is too large to put on the stack, but using malloc
  904.     for small numbers seems expensive. As a compromise, the stack is used when
  905.     there are no more than REC_STACK_SAVE_MAX values to store; otherwise malloc
  906.     is used. A problem is what to do if the malloc fails ... there is no way of
  907.     returning to the top level with an error. Save the top REC_STACK_SAVE_MAX
  908.     values on the stack, and accept that the rest may be wrong.
  909.  
  910.     There are also other values that have to be saved. We use a chained
  911.     sequence of blocks that actually live on the stack. Thanks to Robin Houston
  912.     for the original version of this logic. */
  913.  
  914.     case OP_RECURSE:
  915.       {
  916.       callpat = md->start_code + GET(ecode, 1);
  917.       new_recursive.group_num = (callpat == md->start_code)? 0 :
  918.         GET2(callpat, 1 + LINK_SIZE);
  919.  
  920.       /* Add to "recursing stack" */
  921.  
  922.       new_recursive.prevrec = md->recursive;
  923.       md->recursive = &new_recursive;
  924.  
  925.       /* Find where to continue from afterwards */
  926.  
  927.       ecode += 1 + LINK_SIZE;
  928.       new_recursive.after_call = ecode;
  929.  
  930.       /* Now save the offset data. */
  931.  
  932.       new_recursive.saved_max = md->offset_end;
  933.       if (new_recursive.saved_max <= REC_STACK_SAVE_MAX)
  934.         new_recursive.offset_save = stacksave;
  935.       else
  936.         {
  937.         new_recursive.offset_save =
  938.           (int *)(pcre_malloc)(new_recursive.saved_max * sizeof(int));
  939.         if (new_recursive.offset_save == NULL) RRETURN(PCRE_ERROR_NOMEMORY);
  940.         }
  941.  
  942.       memcpy(new_recursive.offset_save, md->offset_vector,
  943.             new_recursive.saved_max * sizeof(int));
  944.       new_recursive.save_start = md->start_match;
  945.       md->start_match = eptr;
  946.  
  947.       /* OK, now we can do the recursion. For each top-level alternative we
  948.       restore the offset and recursion data. */
  949.  
  950.       DPRINTF(("Recursing into group %d\n", new_recursive.group_num));
  951.       flags = (*callpat >= OP_SBRA)? match_cbegroup : 0;
  952.       do
  953.         {
  954.         RMATCH(rrc, eptr, callpat + _pcre_OP_lengths[*callpat], offset_top,
  955.           md, ims, eptrb, flags);
  956.         if (rrc == MATCH_MATCH)
  957.           {
  958.           DPRINTF(("Recursion matched\n"));
  959.           md->recursive = new_recursive.prevrec;
  960.           if (new_recursive.offset_save != stacksave)
  961.             (pcre_free)(new_recursive.offset_save);
  962.           RRETURN(MATCH_MATCH);
  963.           }
  964.         else if (rrc != MATCH_NOMATCH)
  965.           {
  966.           DPRINTF(("Recursion gave error %d\n", rrc));
  967.           RRETURN(rrc);
  968.           }
  969.  
  970.         md->recursive = &new_recursive;
  971.         memcpy(md->offset_vector, new_recursive.offset_save,
  972.             new_recursive.saved_max * sizeof(int));
  973.         callpat += GET(callpat, 1);
  974.         }
  975.       while (*callpat == OP_ALT);
  976.  
  977.       DPRINTF(("Recursion didn't match\n"));
  978.       md->recursive = new_recursive.prevrec;
  979.       if (new_recursive.offset_save != stacksave)
  980.         (pcre_free)(new_recursive.offset_save);
  981.       RRETURN(MATCH_NOMATCH);
  982.       }
  983.     /* Control never reaches here */
  984.  
  985.     /* "Once" brackets are like assertion brackets except that after a match,
  986.     the point in the subject string is not moved back. Thus there can never be
  987.     a move back into the brackets. Friedl calls these "atomic" subpatterns.
  988.     Check the alternative branches in turn - the matching won't pass the KET
  989.     for this kind of subpattern. If any one branch matches, we carry on as at
  990.     the end of a normal bracket, leaving the subject pointer. */
  991.  
  992.     case OP_ONCE:
  993.     prev = ecode;
  994.     saved_eptr = eptr;
  995.  
  996.     do
  997.       {
  998.       RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims,
  999.         eptrb, 0);
  1000.       if (rrc == MATCH_MATCH) break;
  1001.       if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  1002.       ecode += GET(ecode,1);
  1003.       }
  1004.     while (*ecode == OP_ALT);
  1005.  
  1006.     /* If hit the end of the group (which could be repeated), fail */
  1007.  
  1008.     if (*ecode != OP_ONCE && *ecode != OP_ALT) RRETURN(MATCH_NOMATCH);
  1009.  
  1010.     /* Continue as from after the assertion, updating the offsets high water
  1011.     mark, since extracts may have been taken. */
  1012.  
  1013.     do ecode += GET(ecode, 1); while (*ecode == OP_ALT);
  1014.  
  1015.     offset_top = md->end_offset_top;
  1016.     eptr = md->end_match_ptr;
  1017.  
  1018.     /* For a non-repeating ket, just continue at this level. This also
  1019.     happens for a repeating ket if no characters were matched in the group.
  1020.     This is the forcible breaking of infinite loops as implemented in Perl
  1021.     5.005. If there is an options reset, it will get obeyed in the normal
  1022.     course of events. */
  1023.  
  1024.     if (*ecode == OP_KET || eptr == saved_eptr)
  1025.       {
  1026.       ecode += 1+LINK_SIZE;
  1027.       break;
  1028.       }
  1029.  
  1030.     /* The repeating kets try the rest of the pattern or restart from the
  1031.     preceding bracket, in the appropriate order. The second "call" of match()
  1032.     uses tail recursion, to avoid using another stack frame. We need to reset
  1033.     any options that changed within the bracket before re-running it, so
  1034.     check the next opcode. */
  1035.  
  1036.     if (ecode[1+LINK_SIZE] == OP_OPT)
  1037.       {
  1038.       ims = (ims & ~PCRE_IMS) | ecode[4];
  1039.       DPRINTF(("ims set to %02lx at group repeat\n", ims));
  1040.       }
  1041.  
  1042.     if (*ecode == OP_KETRMIN)
  1043.       {
  1044.       RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0);
  1045.       if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  1046.       ecode = prev;
  1047.       flags = match_tail_recursed;
  1048.       goto TAIL_RECURSE;
  1049.       }
  1050.     else  /* OP_KETRMAX */
  1051.       {
  1052.       RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_cbegroup);
  1053.       if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  1054.       ecode += 1 + LINK_SIZE;
  1055.       flags = match_tail_recursed;
  1056.       goto TAIL_RECURSE;
  1057.       }
  1058.     /* Control never gets here */
  1059.  
  1060.     /* An alternation is the end of a branch; scan along to find the end of the
  1061.     bracketed group and go to there. */
  1062.  
  1063.     case OP_ALT:
  1064.     do ecode += GET(ecode,1); while (*ecode == OP_ALT);
  1065.     break;
  1066.  
  1067.     /* BRAZERO and BRAMINZERO occur just before a bracket group, indicating
  1068.     that it may occur zero times. It may repeat infinitely, or not at all -
  1069.     i.e. it could be ()* or ()? in the pattern. Brackets with fixed upper
  1070.     repeat limits are compiled as a number of copies, with the optional ones
  1071.     preceded by BRAZERO or BRAMINZERO. */
  1072.  
  1073.     case OP_BRAZERO:
  1074.       {
  1075.       next = ecode+1;
  1076.       RMATCH(rrc, eptr, next, offset_top, md, ims, eptrb, 0);
  1077.       if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  1078.       do next += GET(next,1); while (*next == OP_ALT);
  1079.       ecode = next + 1 + LINK_SIZE;
  1080.       }
  1081.     break;
  1082.  
  1083.     case OP_BRAMINZERO:
  1084.       {
  1085.       next = ecode+1;
  1086.       do next += GET(next, 1); while (*next == OP_ALT);
  1087.       RMATCH(rrc, eptr, next + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0);
  1088.       if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  1089.       ecode++;
  1090.       }
  1091.     break;
  1092.  
  1093.     /* End of a group, repeated or non-repeating. */
  1094.  
  1095.     case OP_KET:
  1096.     case OP_KETRMIN:
  1097.     case OP_KETRMAX:
  1098.     prev = ecode - GET(ecode, 1);
  1099.  
  1100.     /* If this was a group that remembered the subject start, in order to break
  1101.     infinite repeats of empty string matches, retrieve the subject start from
  1102.     the chain. Otherwise, set it NULL. */
  1103.  
  1104.     if (*prev >= OP_SBRA)
  1105.       {
  1106.       saved_eptr = eptrb->epb_saved_eptr;   /* Value at start of group */
  1107.       eptrb = eptrb->epb_prev;              /* Backup to previous group */
  1108.       }
  1109.     else saved_eptr = NULL;
  1110.  
  1111.     /* If we are at the end of an assertion group, stop matching and return
  1112.     MATCH_MATCH, but record the current high water mark for use by positive
  1113.     assertions. Do this also for the "once" (atomic) groups. */
  1114.  
  1115.     if (*prev == OP_ASSERT || *prev == OP_ASSERT_NOT ||
  1116.         *prev == OP_ASSERTBACK || *prev == OP_ASSERTBACK_NOT ||
  1117.         *prev == OP_ONCE)
  1118.       {
  1119.       md->end_match_ptr = eptr;      /* For ONCE */
  1120.       md->end_offset_top = offset_top;
  1121.       RRETURN(MATCH_MATCH);
  1122.       }
  1123.  
  1124.     /* For capturing groups we have to check the group number back at the start
  1125.     and if necessary complete handling an extraction by setting the offsets and
  1126.     bumping the high water mark. Note that whole-pattern recursion is coded as
  1127.     a recurse into group 0, so it won't be picked up here. Instead, we catch it
  1128.     when the OP_END is reached. Other recursion is handled here. */
  1129.  
  1130.     if (*prev == OP_CBRA || *prev == OP_SCBRA)
  1131.       {
  1132.       number = GET2(prev, 1+LINK_SIZE);
  1133.       offset = number << 1;
  1134.  
  1135. #ifdef DEBUG
  1136.       printf("end bracket %d", number);
  1137.       printf("\n");
  1138. #endif
  1139.  
  1140.       md->capture_last = number;
  1141.       if (offset >= md->offset_max) md->offset_overflow = TRUE; else
  1142.         {
  1143.         md->offset_vector[offset] =
  1144.           md->offset_vector[md->offset_end - number];
  1145.         md->offset_vector[offset+1] = eptr - md->start_subject;
  1146.         if (offset_top <= offset) offset_top = offset + 2;
  1147.         }
  1148.  
  1149.       /* Handle a recursively called group. Restore the offsets
  1150.       appropriately and continue from after the call. */
  1151.  
  1152.       if (md->recursive != NULL && md->recursive->group_num == number)
  1153.         {
  1154.         recursion_info *rec = md->recursive;
  1155.         DPRINTF(("Recursion (%d) succeeded - continuing\n", number));
  1156.         md->recursive = rec->prevrec;
  1157.         md->start_match = rec->save_start;
  1158.         memcpy(md->offset_vector, rec->offset_save,
  1159.           rec->saved_max * sizeof(int));
  1160.         ecode = rec->after_call;
  1161.         ims = original_ims;
  1162.         break;
  1163.         }
  1164.       }
  1165.  
  1166.     /* For both capturing and non-capturing groups, reset the value of the ims
  1167.     flags, in case they got changed during the group. */
  1168.  
  1169.     ims = original_ims;
  1170.     DPRINTF(("ims reset to %02lx\n", ims));
  1171.  
  1172.     /* For a non-repeating ket, just continue at this level. This also
  1173.     happens for a repeating ket if no characters were matched in the group.
  1174.     This is the forcible breaking of infinite loops as implemented in Perl
  1175.     5.005. If there is an options reset, it will get obeyed in the normal
  1176.     course of events. */
  1177.  
  1178.     if (*ecode == OP_KET || eptr == saved_eptr)
  1179.       {
  1180.       ecode += 1 + LINK_SIZE;
  1181.       break;
  1182.       }
  1183.  
  1184.     /* The repeating kets try the rest of the pattern or restart from the
  1185.     preceding bracket, in the appropriate order. In the second case, we can use
  1186.     tail recursion to avoid using another stack frame. */
  1187.  
  1188.     flags = (*prev >= OP_SBRA)? match_cbegroup : 0;
  1189.  
  1190.     if (*ecode == OP_KETRMIN)
  1191.       {
  1192.       RMATCH(rrc, eptr, ecode + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0);
  1193.       if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  1194.       ecode = prev;
  1195.       flags |= match_tail_recursed;
  1196.       goto TAIL_RECURSE;
  1197.       }
  1198.     else  /* OP_KETRMAX */
  1199.       {
  1200.       RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, flags);
  1201.       if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  1202.       ecode += 1 + LINK_SIZE;
  1203.       flags = match_tail_recursed;
  1204.       goto TAIL_RECURSE;
  1205.       }
  1206.     /* Control never gets here */
  1207.  
  1208.     /* Start of subject unless notbol, or after internal newline if multiline */
  1209.  
  1210.     case OP_CIRC:
  1211.     if (md->notbol && eptr == md->start_subject) RRETURN(MATCH_NOMATCH);
  1212.     if ((ims & PCRE_MULTILINE) != 0)
  1213.       {
  1214.       if (eptr != md->start_subject &&
  1215.           (eptr == md->end_subject || !WAS_NEWLINE(eptr)))
  1216.         RRETURN(MATCH_NOMATCH);
  1217.       ecode++;
  1218.       break;
  1219.       }
  1220.     /* ... else fall through */
  1221.  
  1222.     /* Start of subject assertion */
  1223.  
  1224.     case OP_SOD:
  1225.     if (eptr != md->start_subject) RRETURN(MATCH_NOMATCH);
  1226.     ecode++;
  1227.     break;
  1228.  
  1229.     /* Start of match assertion */
  1230.  
  1231.     case OP_SOM:
  1232.     if (eptr != md->start_subject + md->start_offset) RRETURN(MATCH_NOMATCH);
  1233.     ecode++;
  1234.     break;
  1235.  
  1236.     /* Assert before internal newline if multiline, or before a terminating
  1237.     newline unless endonly is set, else end of subject unless noteol is set. */
  1238.  
  1239.     case OP_DOLL:
  1240.     if ((ims & PCRE_MULTILINE) != 0)
  1241.       {
  1242.       if (eptr < md->end_subject)
  1243.         { if (!IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH); }
  1244.       else
  1245.         { if (md->noteol) RRETURN(MATCH_NOMATCH); }
  1246.       ecode++;
  1247.       break;
  1248.       }
  1249.     else
  1250.       {
  1251.       if (md->noteol) RRETURN(MATCH_NOMATCH);
  1252.       if (!md->endonly)
  1253.         {
  1254.         if (eptr != md->end_subject &&
  1255.             (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen))
  1256.           RRETURN(MATCH_NOMATCH);
  1257.         ecode++;
  1258.         break;
  1259.         }
  1260.       }
  1261.     /* ... else fall through for endonly */
  1262.  
  1263.     /* End of subject assertion (\z) */
  1264.  
  1265.     case OP_EOD:
  1266.     if (eptr < md->end_subject) RRETURN(MATCH_NOMATCH);
  1267.     ecode++;
  1268.     break;
  1269.  
  1270.     /* End of subject or ending \n assertion (\Z) */
  1271.  
  1272.     case OP_EODN:
  1273.     if (eptr != md->end_subject &&
  1274.         (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen))
  1275.       RRETURN(MATCH_NOMATCH);
  1276.     ecode++;
  1277.     break;
  1278.  
  1279.     /* Word boundary assertions */
  1280.  
  1281.     case OP_NOT_WORD_BOUNDARY:
  1282.     case OP_WORD_BOUNDARY:
  1283.       {
  1284.  
  1285.       /* Find out if the previous and current characters are "word" characters.
  1286.       It takes a bit more work in UTF-8 mode. Characters > 255 are assumed to
  1287.       be "non-word" characters. */
  1288.  
  1289. #ifdef SUPPORT_UTF8
  1290.       if (utf8)
  1291.         {
  1292.         if (eptr == md->start_subject) prev_is_word = FALSE; else
  1293.           {
  1294.           const uschar *lastptr = eptr - 1;
  1295.           while((*lastptr & 0xc0) == 0x80) lastptr--;
  1296.           GETCHAR(c, lastptr);
  1297.           prev_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;
  1298.           }
  1299.         if (eptr >= md->end_subject) cur_is_word = FALSE; else
  1300.           {
  1301.           GETCHAR(c, eptr);
  1302.           cur_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;
  1303.           }
  1304.         }
  1305.       else
  1306. #endif
  1307.  
  1308.       /* More streamlined when not in UTF-8 mode */
  1309.  
  1310.         {
  1311.         prev_is_word = (eptr != md->start_subject) &&
  1312.           ((md->ctypes[eptr[-1]] & ctype_word) != 0);
  1313.         cur_is_word = (eptr < md->end_subject) &&
  1314.           ((md->ctypes[*eptr] & ctype_word) != 0);
  1315.         }
  1316.  
  1317.       /* Now see if the situation is what we want */
  1318.  
  1319.       if ((*ecode++ == OP_WORD_BOUNDARY)?
  1320.            cur_is_word == prev_is_word : cur_is_word != prev_is_word)
  1321.         RRETURN(MATCH_NOMATCH);
  1322.       }
  1323.     break;
  1324.  
  1325.     /* Match a single character type; inline for speed */
  1326.  
  1327.     case OP_ANY:
  1328.     if ((ims & PCRE_DOTALL) == 0)
  1329.       {
  1330.       if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
  1331.       }
  1332.     if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH);
  1333. #ifdef SUPPORT_UTF8 /* AutoHotkey: Apparently this line was forgotten because all the other "if utf8" sections have it */
  1334.     if (utf8)
  1335.       while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
  1336. #endif /* AutoHotkey. */
  1337.     ecode++;
  1338.     break;
  1339.  
  1340.     /* Match a single byte, even in UTF-8 mode. This opcode really does match
  1341.     any byte, even newline, independent of the setting of PCRE_DOTALL. */
  1342.  
  1343.     case OP_ANYBYTE:
  1344.     if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH);
  1345.     ecode++;
  1346.     break;
  1347.  
  1348.     case OP_NOT_DIGIT:
  1349.     if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  1350.     GETCHARINCTEST(c, eptr);
  1351.     if (
  1352. #ifdef SUPPORT_UTF8
  1353.        c < 256 &&
  1354. #endif
  1355.        (md->ctypes[c] & ctype_digit) != 0
  1356.        )
  1357.       RRETURN(MATCH_NOMATCH);
  1358.     ecode++;
  1359.     break;
  1360.  
  1361.     case OP_DIGIT:
  1362.     if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  1363.     GETCHARINCTEST(c, eptr);
  1364.     if (
  1365. #ifdef SUPPORT_UTF8
  1366.        c >= 256 ||
  1367. #endif
  1368.        (md->ctypes[c] & ctype_digit) == 0
  1369.        )
  1370.       RRETURN(MATCH_NOMATCH);
  1371.     ecode++;
  1372.     break;
  1373.  
  1374.     case OP_NOT_WHITESPACE:
  1375.     if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  1376.     GETCHARINCTEST(c, eptr);
  1377.     if (
  1378. #ifdef SUPPORT_UTF8
  1379.        c < 256 &&
  1380. #endif
  1381.        (md->ctypes[c] & ctype_space) != 0
  1382.        )
  1383.       RRETURN(MATCH_NOMATCH);
  1384.     ecode++;
  1385.     break;
  1386.  
  1387.     case OP_WHITESPACE:
  1388.     if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  1389.     GETCHARINCTEST(c, eptr);
  1390.     if (
  1391. #ifdef SUPPORT_UTF8
  1392.        c >= 256 ||
  1393. #endif
  1394.        (md->ctypes[c] & ctype_space) == 0
  1395.        )
  1396.       RRETURN(MATCH_NOMATCH);
  1397.     ecode++;
  1398.     break;
  1399.  
  1400.     case OP_NOT_WORDCHAR:
  1401.     if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  1402.     GETCHARINCTEST(c, eptr);
  1403.     if (
  1404. #ifdef SUPPORT_UTF8
  1405.        c < 256 &&
  1406. #endif
  1407.        (md->ctypes[c] & ctype_word) != 0
  1408.        )
  1409.       RRETURN(MATCH_NOMATCH);
  1410.     ecode++;
  1411.     break;
  1412.  
  1413.     case OP_WORDCHAR:
  1414.     if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  1415.     GETCHARINCTEST(c, eptr);
  1416.     if (
  1417. #ifdef SUPPORT_UTF8
  1418.        c >= 256 ||
  1419. #endif
  1420.        (md->ctypes[c] & ctype_word) == 0
  1421.        )
  1422.       RRETURN(MATCH_NOMATCH);
  1423.     ecode++;
  1424.     break;
  1425.  
  1426.     case OP_ANYNL:
  1427.     if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  1428.     GETCHARINCTEST(c, eptr);
  1429.     switch(c)
  1430.       {
  1431.       default: RRETURN(MATCH_NOMATCH);
  1432.       case 0x000d:
  1433.       if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
  1434.       break;
  1435.       case 0x000a:
  1436.       case 0x000b:
  1437.       case 0x000c:
  1438.       case 0x0085:
  1439.       case 0x2028:
  1440.       case 0x2029:
  1441.       break;
  1442.       }
  1443.     ecode++;
  1444.     break;
  1445.  
  1446. #ifdef SUPPORT_UCP
  1447.     /* Check the next character by Unicode property. We will get here only
  1448.     if the support is in the binary; otherwise a compile-time error occurs. */
  1449.  
  1450.     case OP_PROP:
  1451.     case OP_NOTPROP:
  1452.     if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  1453.     GETCHARINCTEST(c, eptr);
  1454.       {
  1455.       int chartype, script;
  1456.       int category = _pcre_ucp_findprop(c, &chartype, &script);
  1457.  
  1458.       switch(ecode[1])
  1459.         {
  1460.         case PT_ANY:
  1461.         if (op == OP_NOTPROP) RRETURN(MATCH_NOMATCH);
  1462.         break;
  1463.  
  1464.         case PT_LAMP:
  1465.         if ((chartype == ucp_Lu ||
  1466.              chartype == ucp_Ll ||
  1467.              chartype == ucp_Lt) == (op == OP_NOTPROP))
  1468.           RRETURN(MATCH_NOMATCH);
  1469.          break;
  1470.  
  1471.         case PT_GC:
  1472.         if ((ecode[2] != category) == (op == OP_PROP))
  1473.           RRETURN(MATCH_NOMATCH);
  1474.         break;
  1475.  
  1476.         case PT_PC:
  1477.         if ((ecode[2] != chartype) == (op == OP_PROP))
  1478.           RRETURN(MATCH_NOMATCH);
  1479.         break;
  1480.  
  1481.         case PT_SC:
  1482.         if ((ecode[2] != script) == (op == OP_PROP))
  1483.           RRETURN(MATCH_NOMATCH);
  1484.         break;
  1485.  
  1486.         default:
  1487.         RRETURN(PCRE_ERROR_INTERNAL);
  1488.         }
  1489.  
  1490.       ecode += 3;
  1491.       }
  1492.     break;
  1493.  
  1494.     /* Match an extended Unicode sequence. We will get here only if the support
  1495.     is in the binary; otherwise a compile-time error occurs. */
  1496.  
  1497.     case OP_EXTUNI:
  1498.     if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  1499.     GETCHARINCTEST(c, eptr);
  1500.       {
  1501.       int chartype, script;
  1502.       int category = _pcre_ucp_findprop(c, &chartype, &script);
  1503.       if (category == ucp_M) RRETURN(MATCH_NOMATCH);
  1504.       while (eptr < md->end_subject)
  1505.         {
  1506.         int len = 1;
  1507.         if (!utf8) c = *eptr; else
  1508.           {
  1509.           GETCHARLEN(c, eptr, len);
  1510.           }
  1511.         category = _pcre_ucp_findprop(c, &chartype, &script);
  1512.         if (category != ucp_M) break;
  1513.         eptr += len;
  1514.         }
  1515.       }
  1516.     ecode++;
  1517.     break;
  1518. #endif
  1519.  
  1520.  
  1521.     /* Match a back reference, possibly repeatedly. Look past the end of the
  1522.     item to see if there is repeat information following. The code is similar
  1523.     to that for character classes, but repeated for efficiency. Then obey
  1524.     similar code to character type repeats - written out again for speed.
  1525.     However, if the referenced string is the empty string, always treat
  1526.     it as matched, any number of times (otherwise there could be infinite
  1527.     loops). */
  1528.  
  1529.     case OP_REF:
  1530.       {
  1531.       offset = GET2(ecode, 1) << 1;               /* Doubled ref number */
  1532.       ecode += 3;                                 /* Advance past item */
  1533.  
  1534.       /* If the reference is unset, set the length to be longer than the amount
  1535.       of subject left; this ensures that every attempt at a match fails. We
  1536.       can't just fail here, because of the possibility of quantifiers with zero
  1537.       minima. */
  1538.  
  1539.       length = (offset >= offset_top || md->offset_vector[offset] < 0)?
  1540.         md->end_subject - eptr + 1 :
  1541.         md->offset_vector[offset+1] - md->offset_vector[offset];
  1542.  
  1543.       /* Set up for repetition, or handle the non-repeated case */
  1544.  
  1545.       switch (*ecode)
  1546.         {
  1547.         case OP_CRSTAR:
  1548.         case OP_CRMINSTAR:
  1549.         case OP_CRPLUS:
  1550.         case OP_CRMINPLUS:
  1551.         case OP_CRQUERY:
  1552.         case OP_CRMINQUERY:
  1553.         c = *ecode++ - OP_CRSTAR;
  1554.         minimize = (c & 1) != 0;
  1555.         min = rep_min[c];                 /* Pick up values from tables; */
  1556.         max = rep_max[c];                 /* zero for max => infinity */
  1557.         if (max == 0) max = INT_MAX;
  1558.         break;
  1559.  
  1560.         case OP_CRRANGE:
  1561.         case OP_CRMINRANGE:
  1562.         minimize = (*ecode == OP_CRMINRANGE);
  1563.         min = GET2(ecode, 1);
  1564.         max = GET2(ecode, 3);
  1565.         if (max == 0) max = INT_MAX;
  1566.         ecode += 5;
  1567.         break;
  1568.  
  1569.         default:               /* No repeat follows */
  1570.         if (!match_ref(offset, eptr, length, md, ims)) RRETURN(MATCH_NOMATCH);
  1571.         eptr += length;
  1572.         continue;              /* With the main loop */
  1573.         }
  1574.  
  1575.       /* If the length of the reference is zero, just continue with the
  1576.       main loop. */
  1577.  
  1578.       if (length == 0) continue;
  1579.  
  1580.       /* First, ensure the minimum number of matches are present. We get back
  1581.       the length of the reference string explicitly rather than passing the
  1582.       address of eptr, so that eptr can be a register variable. */
  1583.  
  1584.       for (i = 1; i <= min; i++)
  1585.         {
  1586.         if (!match_ref(offset, eptr, length, md, ims)) RRETURN(MATCH_NOMATCH);
  1587.         eptr += length;
  1588.         }
  1589.  
  1590.       /* If min = max, continue at the same level without recursion.
  1591.       They are not both allowed to be zero. */
  1592.  
  1593.       if (min == max) continue;
  1594.  
  1595.       /* If minimizing, keep trying and advancing the pointer */
  1596.  
  1597.       if (minimize)
  1598.         {
  1599.         for (fi = min;; fi++)
  1600.           {
  1601.           RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
  1602.           if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  1603.           if (fi >= max || !match_ref(offset, eptr, length, md, ims))
  1604.             RRETURN(MATCH_NOMATCH);
  1605.           eptr += length;
  1606.           }
  1607.         /* Control never gets here */
  1608.         }
  1609.  
  1610.       /* If maximizing, find the longest string and work backwards */
  1611.  
  1612.       else
  1613.         {
  1614.         pp = eptr;
  1615.         for (i = min; i < max; i++)
  1616.           {
  1617.           if (!match_ref(offset, eptr, length, md, ims)) break;
  1618.           eptr += length;
  1619.           }
  1620.         while (eptr >= pp)
  1621.           {
  1622.           RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
  1623.           if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  1624.           eptr -= length;
  1625.           }
  1626.         RRETURN(MATCH_NOMATCH);
  1627.         }
  1628.       }
  1629.     /* Control never gets here */
  1630.  
  1631.  
  1632.  
  1633.     /* Match a bit-mapped character class, possibly repeatedly. This op code is
  1634.     used when all the characters in the class have values in the range 0-255,
  1635.     and either the matching is caseful, or the characters are in the range
  1636.     0-127 when UTF-8 processing is enabled. The only difference between
  1637.     OP_CLASS and OP_NCLASS occurs when a data character outside the range is
  1638.     encountered.
  1639.  
  1640.     First, look past the end of the item to see if there is repeat information
  1641.     following. Then obey similar code to character type repeats - written out
  1642.     again for speed. */
  1643.  
  1644.     case OP_NCLASS:
  1645.     case OP_CLASS:
  1646.       {
  1647.       data = ecode + 1;                /* Save for matching */
  1648.       ecode += 33;                     /* Advance past the item */
  1649.  
  1650.       switch (*ecode)
  1651.         {
  1652.         case OP_CRSTAR:
  1653.         case OP_CRMINSTAR:
  1654.         case OP_CRPLUS:
  1655.         case OP_CRMINPLUS:
  1656.         case OP_CRQUERY:
  1657.         case OP_CRMINQUERY:
  1658.         c = *ecode++ - OP_CRSTAR;
  1659.         minimize = (c & 1) != 0;
  1660.         min = rep_min[c];                 /* Pick up values from tables; */
  1661.         max = rep_max[c];                 /* zero for max => infinity */
  1662.         if (max == 0) max = INT_MAX;
  1663.         break;
  1664.  
  1665.         case OP_CRRANGE:
  1666.         case OP_CRMINRANGE:
  1667.         minimize = (*ecode == OP_CRMINRANGE);
  1668.         min = GET2(ecode, 1);
  1669.         max = GET2(ecode, 3);
  1670.         if (max == 0) max = INT_MAX;
  1671.         ecode += 5;
  1672.         break;
  1673.  
  1674.         default:               /* No repeat follows */
  1675.         min = max = 1;
  1676.         break;
  1677.         }
  1678.  
  1679.       /* First, ensure the minimum number of matches are present. */
  1680.  
  1681. #ifdef SUPPORT_UTF8
  1682.       /* UTF-8 mode */
  1683.       if (utf8)
  1684.         {
  1685.         for (i = 1; i <= min; i++)
  1686.           {
  1687.           if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  1688.           GETCHARINC(c, eptr);
  1689.           if (c > 255)
  1690.             {
  1691.             if (op == OP_CLASS) RRETURN(MATCH_NOMATCH);
  1692.             }
  1693.           else
  1694.             {
  1695.             if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);
  1696.             }
  1697.           }
  1698.         }
  1699.       else
  1700. #endif
  1701.       /* Not UTF-8 mode */
  1702.         {
  1703.         for (i = 1; i <= min; i++)
  1704.           {
  1705.           if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  1706.           c = *eptr++;
  1707.           if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);
  1708.           }
  1709.         }
  1710.  
  1711.       /* If max == min we can continue with the main loop without the
  1712.       need to recurse. */
  1713.  
  1714.       if (min == max) continue;
  1715.  
  1716.       /* If minimizing, keep testing the rest of the expression and advancing
  1717.       the pointer while it matches the class. */
  1718.  
  1719.       if (minimize)
  1720.         {
  1721. #ifdef SUPPORT_UTF8
  1722.         /* UTF-8 mode */
  1723.         if (utf8)
  1724.           {
  1725.           for (fi = min;; fi++)
  1726.             {
  1727.             RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
  1728.             if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  1729.             if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  1730.             GETCHARINC(c, eptr);
  1731.             if (c > 255)
  1732.               {
  1733.               if (op == OP_CLASS) RRETURN(MATCH_NOMATCH);
  1734.               }
  1735.             else
  1736.               {
  1737.               if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);
  1738.               }
  1739.             }
  1740.           }
  1741.         else
  1742. #endif
  1743.         /* Not UTF-8 mode */
  1744.           {
  1745.           for (fi = min;; fi++)
  1746.             {
  1747.             RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
  1748.             if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  1749.             if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  1750.             c = *eptr++;
  1751.             if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);
  1752.             }
  1753.           }
  1754.         /* Control never gets here */
  1755.         }
  1756.  
  1757.       /* If maximizing, find the longest possible run, then work backwards. */
  1758.  
  1759.       else
  1760.         {
  1761.         pp = eptr;
  1762.  
  1763. #ifdef SUPPORT_UTF8
  1764.         /* UTF-8 mode */
  1765.         if (utf8)
  1766.           {
  1767.           for (i = min; i < max; i++)
  1768.             {
  1769.             int len = 1;
  1770.             if (eptr >= md->end_subject) break;
  1771.             GETCHARLEN(c, eptr, len);
  1772.             if (c > 255)
  1773.               {
  1774.               if (op == OP_CLASS) break;
  1775.               }
  1776.             else
  1777.               {
  1778.               if ((data[c/8] & (1 << (c&7))) == 0) break;
  1779.               }
  1780.             eptr += len;
  1781.             }
  1782.           for (;;)
  1783.             {
  1784.             RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
  1785.             if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  1786.             if (eptr-- == pp) break;        /* Stop if tried at original pos */
  1787.             BACKCHAR(eptr);
  1788.             }
  1789.           }
  1790.         else
  1791. #endif
  1792.           /* Not UTF-8 mode */
  1793.           {
  1794.           for (i = min; i < max; i++)
  1795.             {
  1796.             if (eptr >= md->end_subject) break;
  1797.             c = *eptr;
  1798.             if ((data[c/8] & (1 << (c&7))) == 0) break;
  1799.             eptr++;
  1800.             }
  1801.           while (eptr >= pp)
  1802.             {
  1803.             RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
  1804.             if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  1805.             eptr--;
  1806.             }
  1807.           }
  1808.  
  1809.         RRETURN(MATCH_NOMATCH);
  1810.         }
  1811.       }
  1812.     /* Control never gets here */
  1813.  
  1814.  
  1815.     /* Match an extended character class. This opcode is encountered only
  1816.     in UTF-8 mode, because that's the only time it is compiled. */
  1817.  
  1818. #ifdef SUPPORT_UTF8
  1819.     case OP_XCLASS:
  1820.       {
  1821.       data = ecode + 1 + LINK_SIZE;                /* Save for matching */
  1822.       ecode += GET(ecode, 1);                      /* Advance past the item */
  1823.  
  1824.       switch (*ecode)
  1825.         {
  1826.         case OP_CRSTAR:
  1827.         case OP_CRMINSTAR:
  1828.         case OP_CRPLUS:
  1829.         case OP_CRMINPLUS:
  1830.         case OP_CRQUERY:
  1831.         case OP_CRMINQUERY:
  1832.         c = *ecode++ - OP_CRSTAR;
  1833.         minimize = (c & 1) != 0;
  1834.         min = rep_min[c];                 /* Pick up values from tables; */
  1835.         max = rep_max[c];                 /* zero for max => infinity */
  1836.         if (max == 0) max = INT_MAX;
  1837.         break;
  1838.  
  1839.         case OP_CRRANGE:
  1840.         case OP_CRMINRANGE:
  1841.         minimize = (*ecode == OP_CRMINRANGE);
  1842.         min = GET2(ecode, 1);
  1843.         max = GET2(ecode, 3);
  1844.         if (max == 0) max = INT_MAX;
  1845.         ecode += 5;
  1846.         break;
  1847.  
  1848.         default:               /* No repeat follows */
  1849.         min = max = 1;
  1850.         break;
  1851.         }
  1852.  
  1853.       /* First, ensure the minimum number of matches are present. */
  1854.  
  1855.       for (i = 1; i <= min; i++)
  1856.         {
  1857.         if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  1858.         GETCHARINC(c, eptr);
  1859.         if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);
  1860.         }
  1861.  
  1862.       /* If max == min we can continue with the main loop without the
  1863.       need to recurse. */
  1864.  
  1865.       if (min == max) continue;
  1866.  
  1867.       /* If minimizing, keep testing the rest of the expression and advancing
  1868.       the pointer while it matches the class. */
  1869.  
  1870.       if (minimize)
  1871.         {
  1872.         for (fi = min;; fi++)
  1873.           {
  1874.           RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
  1875.           if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  1876.           if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  1877.           GETCHARINC(c, eptr);
  1878.           if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);
  1879.           }
  1880.         /* Control never gets here */
  1881.         }
  1882.  
  1883.       /* If maximizing, find the longest possible run, then work backwards. */
  1884.  
  1885.       else
  1886.         {
  1887.         pp = eptr;
  1888.         for (i = min; i < max; i++)
  1889.           {
  1890.           int len = 1;
  1891.           if (eptr >= md->end_subject) break;
  1892.           GETCHARLEN(c, eptr, len);
  1893.           if (!_pcre_xclass(c, data)) break;
  1894.           eptr += len;
  1895.           }
  1896.         for(;;)
  1897.           {
  1898.           RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
  1899.           if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  1900.           if (eptr-- == pp) break;        /* Stop if tried at original pos */
  1901.           BACKCHAR(eptr)
  1902.           }
  1903.         RRETURN(MATCH_NOMATCH);
  1904.         }
  1905.  
  1906.       /* Control never gets here */
  1907.       }
  1908. #endif    /* End of XCLASS */
  1909.  
  1910.     /* Match a single character, casefully */
  1911.  
  1912.     case OP_CHAR:
  1913. #ifdef SUPPORT_UTF8
  1914.     if (utf8)
  1915.       {
  1916.       length = 1;
  1917.       ecode++;
  1918.       GETCHARLEN(fc, ecode, length);
  1919.       if (length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);
  1920.       while (length-- > 0) if (*ecode++ != *eptr++) RRETURN(MATCH_NOMATCH);
  1921.       }
  1922.     else
  1923. #endif
  1924.  
  1925.     /* Non-UTF-8 mode */
  1926.       {
  1927.       if (md->end_subject - eptr < 1) RRETURN(MATCH_NOMATCH);
  1928.       if (ecode[1] != *eptr++) RRETURN(MATCH_NOMATCH);
  1929.       ecode += 2;
  1930.       }
  1931.     break;
  1932.  
  1933.     /* Match a single character, caselessly */
  1934.  
  1935.     case OP_CHARNC:
  1936. #ifdef SUPPORT_UTF8
  1937.     if (utf8)
  1938.       {
  1939.       length = 1;
  1940.       ecode++;
  1941.       GETCHARLEN(fc, ecode, length);
  1942.  
  1943.       if (length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);
  1944.  
  1945.       /* If the pattern character's value is < 128, we have only one byte, and
  1946.       can use the fast lookup table. */
  1947.  
  1948.       if (fc < 128)
  1949.         {
  1950.         if (md->lcc[*ecode++] != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);
  1951.         }
  1952.  
  1953.       /* Otherwise we must pick up the subject character */
  1954.  
  1955.       else
  1956.         {
  1957.         unsigned int dc;
  1958.         GETCHARINC(dc, eptr);
  1959.         ecode += length;
  1960.  
  1961.         /* If we have Unicode property support, we can use it to test the other
  1962.         case of the character, if there is one. */
  1963.  
  1964.         if (fc != dc)
  1965.           {
  1966. #ifdef SUPPORT_UCP
  1967.           if (dc != _pcre_ucp_othercase(fc))
  1968. #endif
  1969.             RRETURN(MATCH_NOMATCH);
  1970.           }
  1971.         }
  1972.       }
  1973.     else
  1974. #endif   /* SUPPORT_UTF8 */
  1975.  
  1976.     /* Non-UTF-8 mode */
  1977.       {
  1978.       if (md->end_subject - eptr < 1) RRETURN(MATCH_NOMATCH);
  1979.       if (md->lcc[ecode[1]] != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);
  1980.       ecode += 2;
  1981.       }
  1982.     break;
  1983.  
  1984.     /* Match a single character repeatedly. */
  1985.  
  1986.     case OP_EXACT:
  1987.     min = max = GET2(ecode, 1);
  1988.     ecode += 3;
  1989.     goto REPEATCHAR;
  1990.  
  1991.     case OP_POSUPTO:
  1992.     possessive = TRUE;
  1993.     /* Fall through */
  1994.  
  1995.     case OP_UPTO:
  1996.     case OP_MINUPTO:
  1997.     min = 0;
  1998.     max = GET2(ecode, 1);
  1999.     minimize = *ecode == OP_MINUPTO;
  2000.     ecode += 3;
  2001.     goto REPEATCHAR;
  2002.  
  2003.     case OP_POSSTAR:
  2004.     possessive = TRUE;
  2005.     min = 0;
  2006.     max = INT_MAX;
  2007.     ecode++;
  2008.     goto REPEATCHAR;
  2009.  
  2010.     case OP_POSPLUS:
  2011.     possessive = TRUE;
  2012.     min = 1;
  2013.     max = INT_MAX;
  2014.     ecode++;
  2015.     goto REPEATCHAR;
  2016.  
  2017.     case OP_POSQUERY:
  2018.     possessive = TRUE;
  2019.     min = 0;
  2020.     max = 1;
  2021.     ecode++;
  2022.     goto REPEATCHAR;
  2023.  
  2024.     case OP_STAR:
  2025.     case OP_MINSTAR:
  2026.     case OP_PLUS:
  2027.     case OP_MINPLUS:
  2028.     case OP_QUERY:
  2029.     case OP_MINQUERY:
  2030.     c = *ecode++ - OP_STAR;
  2031.     minimize = (c & 1) != 0;
  2032.     min = rep_min[c];                 /* Pick up values from tables; */
  2033.     max = rep_max[c];                 /* zero for max => infinity */
  2034.     if (max == 0) max = INT_MAX;
  2035.  
  2036.     /* Common code for all repeated single-character matches. We can give
  2037.     up quickly if there are fewer than the minimum number of characters left in
  2038.     the subject. */
  2039.  
  2040.     REPEATCHAR:
  2041. #ifdef SUPPORT_UTF8
  2042.     if (utf8)
  2043.       {
  2044.       length = 1;
  2045.       charptr = ecode;
  2046.       GETCHARLEN(fc, ecode, length);
  2047.       if (min * length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);
  2048.       ecode += length;
  2049.  
  2050.       /* Handle multibyte character matching specially here. There is
  2051.       support for caseless matching if UCP support is present. */
  2052.  
  2053.       if (length > 1)
  2054.         {
  2055.         int oclength = 0;
  2056.         uschar occhars[8];
  2057.  
  2058. #ifdef SUPPORT_UCP
  2059.         unsigned int othercase;
  2060.         if ((ims & PCRE_CASELESS) != 0 &&
  2061.             (othercase = _pcre_ucp_othercase(fc)) != NOTACHAR)
  2062.           oclength = _pcre_ord2utf8(othercase, occhars);
  2063. #endif  /* SUPPORT_UCP */
  2064.  
  2065.         for (i = 1; i <= min; i++)
  2066.           {
  2067.           if (memcmp(eptr, charptr, length) == 0) eptr += length;
  2068.           /* Need braces because of following else */
  2069.           else if (oclength == 0) { RRETURN(MATCH_NOMATCH); }
  2070.           else
  2071.             {
  2072.             if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH);
  2073.             eptr += oclength;
  2074.             }
  2075.           }
  2076.  
  2077.         if (min == max) continue;
  2078.  
  2079.         if (minimize)
  2080.           {
  2081.           for (fi = min;; fi++)
  2082.             {
  2083.             RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
  2084.             if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  2085.             if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  2086.             if (memcmp(eptr, charptr, length) == 0) eptr += length;
  2087.             /* Need braces because of following else */
  2088.             else if (oclength == 0) { RRETURN(MATCH_NOMATCH); }
  2089.             else
  2090.               {
  2091.               if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH);
  2092.               eptr += oclength;
  2093.               }
  2094.             }
  2095.           /* Control never gets here */
  2096.           }
  2097.  
  2098.         else  /* Maximize */
  2099.           {
  2100.           pp = eptr;
  2101.           for (i = min; i < max; i++)
  2102.             {
  2103.             if (eptr > md->end_subject - length) break;
  2104.             if (memcmp(eptr, charptr, length) == 0) eptr += length;
  2105.             else if (oclength == 0) break;
  2106.             else
  2107.               {
  2108.               if (memcmp(eptr, occhars, oclength) != 0) break;
  2109.               eptr += oclength;
  2110.               }
  2111.             }
  2112.  
  2113.           if (possessive) continue;
  2114.           while (eptr >= pp)
  2115.            {
  2116.            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
  2117.            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  2118.            eptr -= length;
  2119.            }
  2120.           RRETURN(MATCH_NOMATCH);
  2121.           }
  2122.         /* Control never gets here */
  2123.         }
  2124.  
  2125.       /* If the length of a UTF-8 character is 1, we fall through here, and
  2126.       obey the code as for non-UTF-8 characters below, though in this case the
  2127.       value of fc will always be < 128. */
  2128.       }
  2129.     else
  2130. #endif  /* SUPPORT_UTF8 */
  2131.  
  2132.     /* When not in UTF-8 mode, load a single-byte character. */
  2133.       {
  2134.       if (min > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);
  2135.       fc = *ecode++;
  2136.       }
  2137.  
  2138.     /* The value of fc at this point is always less than 256, though we may or
  2139.     may not be in UTF-8 mode. The code is duplicated for the caseless and
  2140.     caseful cases, for speed, since matching characters is likely to be quite
  2141.     common. First, ensure the minimum number of matches are present. If min =
  2142.     max, continue at the same level without recursing. Otherwise, if
  2143.     minimizing, keep trying the rest of the expression and advancing one
  2144.     matching character if failing, up to the maximum. Alternatively, if
  2145.     maximizing, find the maximum number of characters and work backwards. */
  2146.  
  2147.     DPRINTF(("matching %c{%d,%d} against subject %.*s\n", fc, min, max,
  2148.       max, eptr));
  2149.  
  2150.     if ((ims & PCRE_CASELESS) != 0)
  2151.       {
  2152.       fc = md->lcc[fc];
  2153.       for (i = 1; i <= min; i++)
  2154.         if (fc != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);
  2155.       if (min == max) continue;
  2156.       if (minimize)
  2157.         {
  2158.         for (fi = min;; fi++)
  2159.           {
  2160.           RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
  2161.           if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  2162.           if (fi >= max || eptr >= md->end_subject ||
  2163.               fc != md->lcc[*eptr++])
  2164.             RRETURN(MATCH_NOMATCH);
  2165.           }
  2166.         /* Control never gets here */
  2167.         }
  2168.       else  /* Maximize */
  2169.         {
  2170.         pp = eptr;
  2171.         for (i = min; i < max; i++)
  2172.           {
  2173.           if (eptr >= md->end_subject || fc != md->lcc[*eptr]) break;
  2174.           eptr++;
  2175.           }
  2176.         if (possessive) continue;
  2177.         while (eptr >= pp)
  2178.           {
  2179.           RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
  2180.           eptr--;
  2181.           if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  2182.           }
  2183.         RRETURN(MATCH_NOMATCH);
  2184.         }
  2185.       /* Control never gets here */
  2186.       }
  2187.  
  2188.     /* Caseful comparisons (includes all multi-byte characters) */
  2189.  
  2190.     else
  2191.       {
  2192.       for (i = 1; i <= min; i++) if (fc != *eptr++) RRETURN(MATCH_NOMATCH);
  2193.       if (min == max) continue;
  2194.       if (minimize)
  2195.         {
  2196.         for (fi = min;; fi++)
  2197.           {
  2198.           RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
  2199.           if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  2200.           if (fi >= max || eptr >= md->end_subject || fc != *eptr++)
  2201.             RRETURN(MATCH_NOMATCH);
  2202.           }
  2203.         /* Control never gets here */
  2204.         }
  2205.       else  /* Maximize */
  2206.         {
  2207.         pp = eptr;
  2208.         for (i = min; i < max; i++)
  2209.           {
  2210.           if (eptr >= md->end_subject || fc != *eptr) break;
  2211.           eptr++;
  2212.           }
  2213.         if (possessive) continue;
  2214.         while (eptr >= pp)
  2215.           {
  2216.           RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
  2217.           eptr--;
  2218.           if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  2219.           }
  2220.         RRETURN(MATCH_NOMATCH);
  2221.         }
  2222.       }
  2223.     /* Control never gets here */
  2224.  
  2225.     /* Match a negated single one-byte character. The character we are
  2226.     checking can be multibyte. */
  2227.  
  2228.     case OP_NOT:
  2229.     if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  2230.     ecode++;
  2231.     GETCHARINCTEST(c, eptr);
  2232.     if ((ims & PCRE_CASELESS) != 0)
  2233.       {
  2234. #ifdef SUPPORT_UTF8
  2235.       if (c < 256)
  2236. #endif
  2237.       c = md->lcc[c];
  2238.       if (md->lcc[*ecode++] == c) RRETURN(MATCH_NOMATCH);
  2239.       }
  2240.     else
  2241.       {
  2242.       if (*ecode++ == c) RRETURN(MATCH_NOMATCH);
  2243.       }
  2244.     break;
  2245.  
  2246.     /* Match a negated single one-byte character repeatedly. This is almost a
  2247.     repeat of the code for a repeated single character, but I haven't found a
  2248.     nice way of commoning these up that doesn't require a test of the
  2249.     positive/negative option for each character match. Maybe that wouldn't add
  2250.     very much to the time taken, but character matching *is* what this is all
  2251.     about... */
  2252.  
  2253.     case OP_NOTEXACT:
  2254.     min = max = GET2(ecode, 1);
  2255.     ecode += 3;
  2256.     goto REPEATNOTCHAR;
  2257.  
  2258.     case OP_NOTUPTO:
  2259.     case OP_NOTMINUPTO:
  2260.     min = 0;
  2261.     max = GET2(ecode, 1);
  2262.     minimize = *ecode == OP_NOTMINUPTO;
  2263.     ecode += 3;
  2264.     goto REPEATNOTCHAR;
  2265.  
  2266.     case OP_NOTPOSSTAR:
  2267.     possessive = TRUE;
  2268.     min = 0;
  2269.     max = INT_MAX;
  2270.     ecode++;
  2271.     goto REPEATNOTCHAR;
  2272.  
  2273.     case OP_NOTPOSPLUS:
  2274.     possessive = TRUE;
  2275.     min = 1;
  2276.     max = INT_MAX;
  2277.     ecode++;
  2278.     goto REPEATNOTCHAR;
  2279.  
  2280.     case OP_NOTPOSQUERY:
  2281.     possessive = TRUE;
  2282.     min = 0;
  2283.     max = 1;
  2284.     ecode++;
  2285.     goto REPEATNOTCHAR;
  2286.  
  2287.     case OP_NOTPOSUPTO:
  2288.     possessive = TRUE;
  2289.     min = 0;
  2290.     max = GET2(ecode, 1);
  2291.     ecode += 3;
  2292.     goto REPEATNOTCHAR;
  2293.  
  2294.     case OP_NOTSTAR:
  2295.     case OP_NOTMINSTAR:
  2296.     case OP_NOTPLUS:
  2297.     case OP_NOTMINPLUS:
  2298.     case OP_NOTQUERY:
  2299.     case OP_NOTMINQUERY:
  2300.     c = *ecode++ - OP_NOTSTAR;
  2301.     minimize = (c & 1) != 0;
  2302.     min = rep_min[c];                 /* Pick up values from tables; */
  2303.     max = rep_max[c];                 /* zero for max => infinity */
  2304.     if (max == 0) max = INT_MAX;
  2305.  
  2306.     /* Common code for all repeated single-byte matches. We can give up quickly
  2307.     if there are fewer than the minimum number of bytes left in the
  2308.     subject. */
  2309.  
  2310.     REPEATNOTCHAR:
  2311.     if (min > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);
  2312.     fc = *ecode++;
  2313.  
  2314.     /* The code is duplicated for the caseless and caseful cases, for speed,
  2315.     since matching characters is likely to be quite common. First, ensure the
  2316.     minimum number of matches are present. If min = max, continue at the same
  2317.     level without recursing. Otherwise, if minimizing, keep trying the rest of
  2318.     the expression and advancing one matching character if failing, up to the
  2319.     maximum. Alternatively, if maximizing, find the maximum number of
  2320.     characters and work backwards. */
  2321.  
  2322.     DPRINTF(("negative matching %c{%d,%d} against subject %.*s\n", fc, min, max,
  2323.       max, eptr));
  2324.  
  2325.     if ((ims & PCRE_CASELESS) != 0)
  2326.       {
  2327.       fc = md->lcc[fc];
  2328.  
  2329. #ifdef SUPPORT_UTF8
  2330.       /* UTF-8 mode */
  2331.       if (utf8)
  2332.         {
  2333.         register unsigned int d;
  2334.         for (i = 1; i <= min; i++)
  2335.           {
  2336.           GETCHARINC(d, eptr);
  2337.           if (d < 256) d = md->lcc[d];
  2338.           if (fc == d) RRETURN(MATCH_NOMATCH);
  2339.           }
  2340.         }
  2341.       else
  2342. #endif
  2343.  
  2344.       /* Not UTF-8 mode */
  2345.         {
  2346.         for (i = 1; i <= min; i++)
  2347.           if (fc == md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);
  2348.         }
  2349.  
  2350.       if (min == max) continue;
  2351.  
  2352.       if (minimize)
  2353.         {
  2354. #ifdef SUPPORT_UTF8
  2355.         /* UTF-8 mode */
  2356.         if (utf8)
  2357.           {
  2358.           register unsigned int d;
  2359.           for (fi = min;; fi++)
  2360.             {
  2361.             RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
  2362.             if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  2363.             GETCHARINC(d, eptr);
  2364.             if (d < 256) d = md->lcc[d];
  2365.             if (fi >= max || eptr >= md->end_subject || fc == d)
  2366.               RRETURN(MATCH_NOMATCH);
  2367.             }
  2368.           }
  2369.         else
  2370. #endif
  2371.         /* Not UTF-8 mode */
  2372.           {
  2373.           for (fi = min;; fi++)
  2374.             {
  2375.             RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
  2376.             if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  2377.             if (fi >= max || eptr >= md->end_subject || fc == md->lcc[*eptr++])
  2378.               RRETURN(MATCH_NOMATCH);
  2379.             }
  2380.           }
  2381.         /* Control never gets here */
  2382.         }
  2383.  
  2384.       /* Maximize case */
  2385.  
  2386.       else
  2387.         {
  2388.         pp = eptr;
  2389.  
  2390. #ifdef SUPPORT_UTF8
  2391.         /* UTF-8 mode */
  2392.         if (utf8)
  2393.           {
  2394.           register unsigned int d;
  2395.           for (i = min; i < max; i++)
  2396.             {
  2397.             int len = 1;
  2398.             if (eptr >= md->end_subject) break;
  2399.             GETCHARLEN(d, eptr, len);
  2400.             if (d < 256) d = md->lcc[d];
  2401.             if (fc == d) break;
  2402.             eptr += len;
  2403.             }
  2404.         if (possessive) continue;
  2405.         for(;;)
  2406.             {
  2407.             RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
  2408.             if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  2409.             if (eptr-- == pp) break;        /* Stop if tried at original pos */
  2410.             BACKCHAR(eptr);
  2411.             }
  2412.           }
  2413.         else
  2414. #endif
  2415.         /* Not UTF-8 mode */
  2416.           {
  2417.           for (i = min; i < max; i++)
  2418.             {
  2419.             if (eptr >= md->end_subject || fc == md->lcc[*eptr]) break;
  2420.             eptr++;
  2421.             }
  2422.           if (possessive) continue;
  2423.           while (eptr >= pp)
  2424.             {
  2425.             RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
  2426.             if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  2427.             eptr--;
  2428.             }
  2429.           }
  2430.  
  2431.         RRETURN(MATCH_NOMATCH);
  2432.         }
  2433.       /* Control never gets here */
  2434.       }
  2435.  
  2436.     /* Caseful comparisons */
  2437.  
  2438.     else
  2439.       {
  2440. #ifdef SUPPORT_UTF8
  2441.       /* UTF-8 mode */
  2442.       if (utf8)
  2443.         {
  2444.         register unsigned int d;
  2445.         for (i = 1; i <= min; i++)
  2446.           {
  2447.           GETCHARINC(d, eptr);
  2448.           if (fc == d) RRETURN(MATCH_NOMATCH);
  2449.           }
  2450.         }
  2451.       else
  2452. #endif
  2453.       /* Not UTF-8 mode */
  2454.         {
  2455.         for (i = 1; i <= min; i++)
  2456.           if (fc == *eptr++) RRETURN(MATCH_NOMATCH);
  2457.         }
  2458.  
  2459.       if (min == max) continue;
  2460.  
  2461.       if (minimize)
  2462.         {
  2463. #ifdef SUPPORT_UTF8
  2464.         /* UTF-8 mode */
  2465.         if (utf8)
  2466.           {
  2467.           register unsigned int d;
  2468.           for (fi = min;; fi++)
  2469.             {
  2470.             RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
  2471.             if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  2472.             GETCHARINC(d, eptr);
  2473.             if (fi >= max || eptr >= md->end_subject || fc == d)
  2474.               RRETURN(MATCH_NOMATCH);
  2475.             }
  2476.           }
  2477.         else
  2478. #endif
  2479.         /* Not UTF-8 mode */
  2480.           {
  2481.           for (fi = min;; fi++)
  2482.             {
  2483.             RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
  2484.             if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  2485.             if (fi >= max || eptr >= md->end_subject || fc == *eptr++)
  2486.               RRETURN(MATCH_NOMATCH);
  2487.             }
  2488.           }
  2489.         /* Control never gets here */
  2490.         }
  2491.  
  2492.       /* Maximize case */
  2493.  
  2494.       else
  2495.         {
  2496.         pp = eptr;
  2497.  
  2498. #ifdef SUPPORT_UTF8
  2499.         /* UTF-8 mode */
  2500.         if (utf8)
  2501.           {
  2502.           register unsigned int d;
  2503.           for (i = min; i < max; i++)
  2504.             {
  2505.             int len = 1;
  2506.             if (eptr >= md->end_subject) break;
  2507.             GETCHARLEN(d, eptr, len);
  2508.             if (fc == d) break;
  2509.             eptr += len;
  2510.             }
  2511.           if (possessive) continue;
  2512.           for(;;)
  2513.             {
  2514.             RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
  2515.             if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  2516.             if (eptr-- == pp) break;        /* Stop if tried at original pos */
  2517.             BACKCHAR(eptr);
  2518.             }
  2519.           }
  2520.         else
  2521. #endif
  2522.         /* Not UTF-8 mode */
  2523.           {
  2524.           for (i = min; i < max; i++)
  2525.             {
  2526.             if (eptr >= md->end_subject || fc == *eptr) break;
  2527.             eptr++;
  2528.             }
  2529.           if (possessive) continue;
  2530.           while (eptr >= pp)
  2531.             {
  2532.             RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
  2533.             if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  2534.             eptr--;
  2535.             }
  2536.           }
  2537.  
  2538.         RRETURN(MATCH_NOMATCH);
  2539.         }
  2540.       }
  2541.     /* Control never gets here */
  2542.  
  2543.     /* Match a single character type repeatedly; several different opcodes
  2544.     share code. This is very similar to the code for single characters, but we
  2545.     repeat it in the interests of efficiency. */
  2546.  
  2547.     case OP_TYPEEXACT:
  2548.     min = max = GET2(ecode, 1);
  2549.     minimize = TRUE;
  2550.     ecode += 3;
  2551.     goto REPEATTYPE;
  2552.  
  2553.     case OP_TYPEUPTO:
  2554.     case OP_TYPEMINUPTO:
  2555.     min = 0;
  2556.     max = GET2(ecode, 1);
  2557.     minimize = *ecode == OP_TYPEMINUPTO;
  2558.     ecode += 3;
  2559.     goto REPEATTYPE;
  2560.  
  2561.     case OP_TYPEPOSSTAR:
  2562.     possessive = TRUE;
  2563.     min = 0;
  2564.     max = INT_MAX;
  2565.     ecode++;
  2566.     goto REPEATTYPE;
  2567.  
  2568.     case OP_TYPEPOSPLUS:
  2569.     possessive = TRUE;
  2570.     min = 1;
  2571.     max = INT_MAX;
  2572.     ecode++;
  2573.     goto REPEATTYPE;
  2574.  
  2575.     case OP_TYPEPOSQUERY:
  2576.     possessive = TRUE;
  2577.     min = 0;
  2578.     max = 1;
  2579.     ecode++;
  2580.     goto REPEATTYPE;
  2581.  
  2582.     case OP_TYPEPOSUPTO:
  2583.     possessive = TRUE;
  2584.     min = 0;
  2585.     max = GET2(ecode, 1);
  2586.     ecode += 3;
  2587.     goto REPEATTYPE;
  2588.  
  2589.     case OP_TYPESTAR:
  2590.     case OP_TYPEMINSTAR:
  2591.     case OP_TYPEPLUS:
  2592.     case OP_TYPEMINPLUS:
  2593.     case OP_TYPEQUERY:
  2594.     case OP_TYPEMINQUERY:
  2595.     c = *ecode++ - OP_TYPESTAR;
  2596.     minimize = (c & 1) != 0;
  2597.     min = rep_min[c];                 /* Pick up values from tables; */
  2598.     max = rep_max[c];                 /* zero for max => infinity */
  2599.     if (max == 0) max = INT_MAX;
  2600.  
  2601.     /* Common code for all repeated single character type matches. Note that
  2602.     in UTF-8 mode, '.' matches a character of any length, but for the other
  2603.     character types, the valid characters are all one-byte long. */
  2604.  
  2605.     REPEATTYPE:
  2606.     ctype = *ecode++;      /* Code for the character type */
  2607.  
  2608. #ifdef SUPPORT_UCP
  2609.     if (ctype == OP_PROP || ctype == OP_NOTPROP)
  2610.       {
  2611.       prop_fail_result = ctype == OP_NOTPROP;
  2612.       prop_type = *ecode++;
  2613.       prop_value = *ecode++;
  2614.       }
  2615.     else prop_type = -1;
  2616. #endif
  2617.  
  2618.     /* First, ensure the minimum number of matches are present. Use inline
  2619.     code for maximizing the speed, and do the type test once at the start
  2620.     (i.e. keep it out of the loop). Also we can test that there are at least
  2621.     the minimum number of bytes before we start. This isn't as effective in
  2622.     UTF-8 mode, but it does no harm. Separate the UTF-8 code completely as that
  2623.     is tidier. Also separate the UCP code, which can be the same for both UTF-8
  2624.     and single-bytes. */
  2625.  
  2626.     if (min > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);
  2627.     if (min > 0)
  2628.       {
  2629. #ifdef SUPPORT_UCP
  2630.       if (prop_type >= 0)
  2631.         {
  2632.         switch(prop_type)
  2633.           {
  2634.           case PT_ANY:
  2635.           if (prop_fail_result) RRETURN(MATCH_NOMATCH);
  2636.           for (i = 1; i <= min; i++)
  2637.             {
  2638.             if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  2639.             GETCHARINC(c, eptr);
  2640.             }
  2641.           break;
  2642.  
  2643.           case PT_LAMP:
  2644.           for (i = 1; i <= min; i++)
  2645.             {
  2646.             if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  2647.             GETCHARINC(c, eptr);
  2648.             prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);
  2649.             if ((prop_chartype == ucp_Lu ||
  2650.                  prop_chartype == ucp_Ll ||
  2651.                  prop_chartype == ucp_Lt) == prop_fail_result)
  2652.               RRETURN(MATCH_NOMATCH);
  2653.             }
  2654.           break;
  2655.  
  2656.           case PT_GC:
  2657.           for (i = 1; i <= min; i++)
  2658.             {
  2659.             if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  2660.             GETCHARINC(c, eptr);
  2661.             prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);
  2662.             if ((prop_category == prop_value) == prop_fail_result)
  2663.               RRETURN(MATCH_NOMATCH);
  2664.             }
  2665.           break;
  2666.  
  2667.           case PT_PC:
  2668.           for (i = 1; i <= min; i++)
  2669.             {
  2670.             if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  2671.             GETCHARINC(c, eptr);
  2672.             prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);
  2673.             if ((prop_chartype == prop_value) == prop_fail_result)
  2674.               RRETURN(MATCH_NOMATCH);
  2675.             }
  2676.           break;
  2677.  
  2678.           case PT_SC:
  2679.           for (i = 1; i <= min; i++)
  2680.             {
  2681.             if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  2682.             GETCHARINC(c, eptr);
  2683.             prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);
  2684.             if ((prop_script == prop_value) == prop_fail_result)
  2685.               RRETURN(MATCH_NOMATCH);
  2686.             }
  2687.           break;
  2688.  
  2689.           default:
  2690.           RRETURN(PCRE_ERROR_INTERNAL);
  2691.           }
  2692.         }
  2693.  
  2694.       /* Match extended Unicode sequences. We will get here only if the
  2695.       support is in the binary; otherwise a compile-time error occurs. */
  2696.  
  2697.       else if (ctype == OP_EXTUNI)
  2698.         {
  2699.         for (i = 1; i <= min; i++)
  2700.           {
  2701.           GETCHARINCTEST(c, eptr);
  2702.           prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);
  2703.           if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);
  2704.           while (eptr < md->end_subject)
  2705.             {
  2706.             int len = 1;
  2707.             if (!utf8) c = *eptr; else
  2708.               {
  2709.               GETCHARLEN(c, eptr, len);
  2710.               }
  2711.             prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);
  2712.             if (prop_category != ucp_M) break;
  2713.             eptr += len;
  2714.             }
  2715.           }
  2716.         }
  2717.  
  2718.       else
  2719. #endif     /* SUPPORT_UCP */
  2720.  
  2721. /* Handle all other cases when the coding is UTF-8 */
  2722.  
  2723. #ifdef SUPPORT_UTF8
  2724.       if (utf8) switch(ctype)
  2725.         {
  2726.         case OP_ANY:
  2727.         for (i = 1; i <= min; i++)
  2728.           {
  2729.           if (eptr >= md->end_subject ||
  2730.                ((ims & PCRE_DOTALL) == 0 && IS_NEWLINE(eptr)))
  2731.             RRETURN(MATCH_NOMATCH);
  2732.           eptr++;
  2733.           while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
  2734.           }
  2735.         break;
  2736.  
  2737.         case OP_ANYBYTE:
  2738.         eptr += min;
  2739.         break;
  2740.  
  2741.         case OP_ANYNL:
  2742.         for (i = 1; i <= min; i++)
  2743.           {
  2744.           if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  2745.           GETCHARINC(c, eptr);
  2746.           switch(c)
  2747.             {
  2748.             default: RRETURN(MATCH_NOMATCH);
  2749.             case 0x000d:
  2750.             if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
  2751.             break;
  2752.             case 0x000a:
  2753.             case 0x000b:
  2754.             case 0x000c:
  2755.             case 0x0085:
  2756.             case 0x2028:
  2757.             case 0x2029:
  2758.             break;
  2759.             }
  2760.           }
  2761.         break;
  2762.  
  2763.         case OP_NOT_DIGIT:
  2764.         for (i = 1; i <= min; i++)
  2765.           {
  2766.           if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  2767.           GETCHARINC(c, eptr);
  2768.           if (c < 128 && (md->ctypes[c] & ctype_digit) != 0)
  2769.             RRETURN(MATCH_NOMATCH);
  2770.           }
  2771.         break;
  2772.  
  2773.         case OP_DIGIT:
  2774.         for (i = 1; i <= min; i++)
  2775.           {
  2776.           if (eptr >= md->end_subject ||
  2777.              *eptr >= 128 || (md->ctypes[*eptr++] & ctype_digit) == 0)
  2778.             RRETURN(MATCH_NOMATCH);
  2779.           /* No need to skip more bytes - we know it's a 1-byte character */
  2780.           }
  2781.         break;
  2782.  
  2783.         case OP_NOT_WHITESPACE:
  2784.         for (i = 1; i <= min; i++)
  2785.           {
  2786.           if (eptr >= md->end_subject ||
  2787.              (*eptr < 128 && (md->ctypes[*eptr++] & ctype_space) != 0))
  2788.             RRETURN(MATCH_NOMATCH);
  2789.           while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
  2790.           }
  2791.         break;
  2792.  
  2793.         case OP_WHITESPACE:
  2794.         for (i = 1; i <= min; i++)
  2795.           {
  2796.           if (eptr >= md->end_subject ||
  2797.              *eptr >= 128 || (md->ctypes[*eptr++] & ctype_space) == 0)
  2798.             RRETURN(MATCH_NOMATCH);
  2799.           /* No need to skip more bytes - we know it's a 1-byte character */
  2800.           }
  2801.         break;
  2802.  
  2803.         case OP_NOT_WORDCHAR:
  2804.         for (i = 1; i <= min; i++)
  2805.           {
  2806.           if (eptr >= md->end_subject ||
  2807.              (*eptr < 128 && (md->ctypes[*eptr++] & ctype_word) != 0))
  2808.             RRETURN(MATCH_NOMATCH);
  2809.           while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
  2810.           }
  2811.         break;
  2812.  
  2813.         case OP_WORDCHAR:
  2814.         for (i = 1; i <= min; i++)
  2815.           {
  2816.           if (eptr >= md->end_subject ||
  2817.              *eptr >= 128 || (md->ctypes[*eptr++] & ctype_word) == 0)
  2818.             RRETURN(MATCH_NOMATCH);
  2819.           /* No need to skip more bytes - we know it's a 1-byte character */
  2820.           }
  2821.         break;
  2822.  
  2823.         default:
  2824.         RRETURN(PCRE_ERROR_INTERNAL);
  2825.         }  /* End switch(ctype) */
  2826.  
  2827.       else
  2828. #endif     /* SUPPORT_UTF8 */
  2829.  
  2830.       /* Code for the non-UTF-8 case for minimum matching of operators other
  2831.       than OP_PROP and OP_NOTPROP. We can assume that there are the minimum
  2832.       number of bytes present, as this was tested above. */
  2833.  
  2834.       switch(ctype)
  2835.         {
  2836.         case OP_ANY:
  2837.         if ((ims & PCRE_DOTALL) == 0)
  2838.           {
  2839.           for (i = 1; i <= min; i++)
  2840.             {
  2841.             if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
  2842.             eptr++;
  2843.             }
  2844.           }
  2845.         else eptr += min;
  2846.         break;
  2847.  
  2848.         case OP_ANYBYTE:
  2849.         eptr += min;
  2850.         break;
  2851.  
  2852.         /* Because of the CRLF case, we can't assume the minimum number of
  2853.         bytes are present in this case. */
  2854.  
  2855.         case OP_ANYNL:
  2856.         for (i = 1; i <= min; i++)
  2857.           {
  2858.           if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  2859.           switch(*eptr++)
  2860.             {
  2861.             default: RRETURN(MATCH_NOMATCH);
  2862.             case 0x000d:
  2863.             if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
  2864.             break;
  2865.             case 0x000a:
  2866.             case 0x000b:
  2867.             case 0x000c:
  2868.             case 0x0085:
  2869.             break;
  2870.             }
  2871.           }
  2872.         break;
  2873.  
  2874.         case OP_NOT_DIGIT:
  2875.         for (i = 1; i <= min; i++)
  2876.           if ((md->ctypes[*eptr++] & ctype_digit) != 0) RRETURN(MATCH_NOMATCH);
  2877.         break;
  2878.  
  2879.         case OP_DIGIT:
  2880.         for (i = 1; i <= min; i++)
  2881.           if ((md->ctypes[*eptr++] & ctype_digit) == 0) RRETURN(MATCH_NOMATCH);
  2882.         break;
  2883.  
  2884.         case OP_NOT_WHITESPACE:
  2885.         for (i = 1; i <= min; i++)
  2886.           if ((md->ctypes[*eptr++] & ctype_space) != 0) RRETURN(MATCH_NOMATCH);
  2887.         break;
  2888.  
  2889.         case OP_WHITESPACE:
  2890.         for (i = 1; i <= min; i++)
  2891.           if ((md->ctypes[*eptr++] & ctype_space) == 0) RRETURN(MATCH_NOMATCH);
  2892.         break;
  2893.  
  2894.         case OP_NOT_WORDCHAR:
  2895.         for (i = 1; i <= min; i++)
  2896.           if ((md->ctypes[*eptr++] & ctype_word) != 0)
  2897.             RRETURN(MATCH_NOMATCH);
  2898.         break;
  2899.  
  2900.         case OP_WORDCHAR:
  2901.         for (i = 1; i <= min; i++)
  2902.           if ((md->ctypes[*eptr++] & ctype_word) == 0)
  2903.             RRETURN(MATCH_NOMATCH);
  2904.         break;
  2905.  
  2906.         default:
  2907.         RRETURN(PCRE_ERROR_INTERNAL);
  2908.         }
  2909.       }
  2910.  
  2911.     /* If min = max, continue at the same level without recursing */
  2912.  
  2913.     if (min == max) continue;
  2914.  
  2915.     /* If minimizing, we have to test the rest of the pattern before each
  2916.     subsequent match. Again, separate the UTF-8 case for speed, and also
  2917.     separate the UCP cases. */
  2918.  
  2919.     if (minimize)
  2920.       {
  2921. #ifdef SUPPORT_UCP
  2922.       if (prop_type >= 0)
  2923.         {
  2924.         switch(prop_type)
  2925.           {
  2926.           case PT_ANY:
  2927.           for (fi = min;; fi++)
  2928.             {
  2929.             RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
  2930.             if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  2931.             if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  2932.             GETCHARINC(c, eptr);
  2933.             if (prop_fail_result) RRETURN(MATCH_NOMATCH);
  2934.             }
  2935.           /* Control never gets here */
  2936.  
  2937.           case PT_LAMP:
  2938.           for (fi = min;; fi++)
  2939.             {
  2940.             RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
  2941.             if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  2942.             if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  2943.             GETCHARINC(c, eptr);
  2944.             prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);
  2945.             if ((prop_chartype == ucp_Lu ||
  2946.                  prop_chartype == ucp_Ll ||
  2947.                  prop_chartype == ucp_Lt) == prop_fail_result)
  2948.               RRETURN(MATCH_NOMATCH);
  2949.             }
  2950.           /* Control never gets here */
  2951.  
  2952.           case PT_GC:
  2953.           for (fi = min;; fi++)
  2954.             {
  2955.             RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
  2956.             if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  2957.             if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  2958.             GETCHARINC(c, eptr);
  2959.             prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);
  2960.             if ((prop_category == prop_value) == prop_fail_result)
  2961.               RRETURN(MATCH_NOMATCH);
  2962.             }
  2963.           /* Control never gets here */
  2964.  
  2965.           case PT_PC:
  2966.           for (fi = min;; fi++)
  2967.             {
  2968.             RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
  2969.             if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  2970.             if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  2971.             GETCHARINC(c, eptr);
  2972.             prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);
  2973.             if ((prop_chartype == prop_value) == prop_fail_result)
  2974.               RRETURN(MATCH_NOMATCH);
  2975.             }
  2976.           /* Control never gets here */
  2977.  
  2978.           case PT_SC:
  2979.           for (fi = min;; fi++)
  2980.             {
  2981.             RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
  2982.             if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  2983.             if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  2984.             GETCHARINC(c, eptr);
  2985.             prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);
  2986.             if ((prop_script == prop_value) == prop_fail_result)
  2987.               RRETURN(MATCH_NOMATCH);
  2988.             }
  2989.           /* Control never gets here */
  2990.  
  2991.           default:
  2992.           RRETURN(PCRE_ERROR_INTERNAL);
  2993.           }
  2994.         }
  2995.  
  2996.       /* Match extended Unicode sequences. We will get here only if the
  2997.       support is in the binary; otherwise a compile-time error occurs. */
  2998.  
  2999.       else if (ctype == OP_EXTUNI)
  3000.         {
  3001.         for (fi = min;; fi++)
  3002.           {
  3003.           RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
  3004.           if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  3005.           if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
  3006.           GETCHARINCTEST(c, eptr);
  3007.           prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);
  3008.           if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);
  3009.           while (eptr < md->end_subject)
  3010.             {
  3011.             int len = 1;
  3012.             if (!utf8) c = *eptr; else
  3013.               {
  3014.               GETCHARLEN(c, eptr, len);
  3015.               }
  3016.             prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);
  3017.             if (prop_category != ucp_M) break;
  3018.             eptr += len;
  3019.             }
  3020.           }
  3021.         }
  3022.  
  3023.       else
  3024. #endif     /* SUPPORT_UCP */
  3025.  
  3026. #ifdef SUPPORT_UTF8
  3027.       /* UTF-8 mode */
  3028.       if (utf8)
  3029.         {
  3030.         for (fi = min;; fi++)
  3031.           {
  3032.           RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
  3033.           if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  3034.           if (fi >= max || eptr >= md->end_subject ||
  3035.                (ctype == OP_ANY && (ims & PCRE_DOTALL) == 0 &&
  3036.                 IS_NEWLINE(eptr)))
  3037.             RRETURN(MATCH_NOMATCH);
  3038.  
  3039.           GETCHARINC(c, eptr);
  3040.           switch(ctype)
  3041.             {
  3042.             case OP_ANY:        /* This is the DOTALL case */
  3043.             break;
  3044.  
  3045.             case OP_ANYBYTE:
  3046.             break;
  3047.  
  3048.             case OP_ANYNL:
  3049.             switch(c)
  3050.               {
  3051.               default: RRETURN(MATCH_NOMATCH);
  3052.               case 0x000d:
  3053.               if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
  3054.               break;
  3055.               case 0x000a:
  3056.               case 0x000b:
  3057.               case 0x000c:
  3058.               case 0x0085:
  3059.               case 0x2028:
  3060.               case 0x2029:
  3061.               break;
  3062.               }
  3063.             break;
  3064.  
  3065.             case OP_NOT_DIGIT:
  3066.             if (c < 256 && (md->ctypes[c] & ctype_digit) != 0)
  3067.               RRETURN(MATCH_NOMATCH);
  3068.             break;
  3069.  
  3070.             case OP_DIGIT:
  3071.             if (c >= 256 || (md->ctypes[c] & ctype_digit) == 0)
  3072.               RRETURN(MATCH_NOMATCH);
  3073.             break;
  3074.  
  3075.             case OP_NOT_WHITESPACE:
  3076.             if (c < 256 && (md->ctypes[c] & ctype_space) != 0)
  3077.               RRETURN(MATCH_NOMATCH);
  3078.             break;
  3079.  
  3080.             case OP_WHITESPACE:
  3081.             if  (c >= 256 || (md->ctypes[c] & ctype_space) == 0)
  3082.               RRETURN(MATCH_NOMATCH);
  3083.             break;
  3084.  
  3085.             case OP_NOT_WORDCHAR:
  3086.             if (c < 256 && (md->ctypes[c] & ctype_word) != 0)
  3087.               RRETURN(MATCH_NOMATCH);
  3088.             break;
  3089.  
  3090.             case OP_WORDCHAR:
  3091.             if (c >= 256 || (md->ctypes[c] & ctype_word) == 0)
  3092.               RRETURN(MATCH_NOMATCH);
  3093.             break;
  3094.  
  3095.             default:
  3096.             RRETURN(PCRE_ERROR_INTERNAL);
  3097.             }
  3098.           }
  3099.         }
  3100.       else
  3101. #endif
  3102.       /* Not UTF-8 mode */
  3103.         {
  3104.         for (fi = min;; fi++)
  3105.           {
  3106.           RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
  3107.           if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  3108.           if (fi >= max || eptr >= md->end_subject ||
  3109.                ((ims & PCRE_DOTALL) == 0 && IS_NEWLINE(eptr)))
  3110.             RRETURN(MATCH_NOMATCH);
  3111.  
  3112.           c = *eptr++;
  3113.           switch(ctype)
  3114.             {
  3115.             case OP_ANY:   /* This is the DOTALL case */
  3116.             break;
  3117.  
  3118.             case OP_ANYBYTE:
  3119.             break;
  3120.  
  3121.             case OP_ANYNL:
  3122.             switch(c)
  3123.               {
  3124.               default: RRETURN(MATCH_NOMATCH);
  3125.               case 0x000d:
  3126.               if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
  3127.               break;
  3128.               case 0x000a:
  3129.               case 0x000b:
  3130.               case 0x000c:
  3131.               case 0x0085:
  3132.               break;
  3133.               }
  3134.             break;
  3135.  
  3136.             case OP_NOT_DIGIT:
  3137.             if ((md->ctypes[c] & ctype_digit) != 0) RRETURN(MATCH_NOMATCH);
  3138.             break;
  3139.  
  3140.             case OP_DIGIT:
  3141.             if ((md->ctypes[c] & ctype_digit) == 0) RRETURN(MATCH_NOMATCH);
  3142.             break;
  3143.  
  3144.             case OP_NOT_WHITESPACE:
  3145.             if ((md->ctypes[c] & ctype_space) != 0) RRETURN(MATCH_NOMATCH);
  3146.             break;
  3147.  
  3148.             case OP_WHITESPACE:
  3149.             if  ((md->ctypes[c] & ctype_space) == 0) RRETURN(MATCH_NOMATCH);
  3150.             break;
  3151.  
  3152.             case OP_NOT_WORDCHAR:
  3153.             if ((md->ctypes[c] & ctype_word) != 0) RRETURN(MATCH_NOMATCH);
  3154.             break;
  3155.  
  3156.             case OP_WORDCHAR:
  3157.             if ((md->ctypes[c] & ctype_word) == 0) RRETURN(MATCH_NOMATCH);
  3158.             break;
  3159.  
  3160.             default:
  3161.             RRETURN(PCRE_ERROR_INTERNAL);
  3162.             }
  3163.           }
  3164.         }
  3165.       /* Control never gets here */
  3166.       }
  3167.  
  3168.     /* If maximizing, it is worth using inline code for speed, doing the type
  3169.     test once at the start (i.e. keep it out of the loop). Again, keep the
  3170.     UTF-8 and UCP stuff separate. */
  3171.  
  3172.     else
  3173.       {
  3174.       pp = eptr;  /* Remember where we started */
  3175.  
  3176. #ifdef SUPPORT_UCP
  3177.       if (prop_type >= 0)
  3178.         {
  3179.         switch(prop_type)
  3180.           {
  3181.           case PT_ANY:
  3182.           for (i = min; i < max; i++)
  3183.             {
  3184.             int len = 1;
  3185.             if (eptr >= md->end_subject) break;
  3186.             GETCHARLEN(c, eptr, len);
  3187.             if (prop_fail_result) break;
  3188.             eptr+= len;
  3189.             }
  3190.           break;
  3191.  
  3192.           case PT_LAMP:
  3193.           for (i = min; i < max; i++)
  3194.             {
  3195.             int len = 1;
  3196.             if (eptr >= md->end_subject) break;
  3197.             GETCHARLEN(c, eptr, len);
  3198.             prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);
  3199.             if ((prop_chartype == ucp_Lu ||
  3200.                  prop_chartype == ucp_Ll ||
  3201.                  prop_chartype == ucp_Lt) == prop_fail_result)
  3202.               break;
  3203.             eptr+= len;
  3204.             }
  3205.           break;
  3206.  
  3207.           case PT_GC:
  3208.           for (i = min; i < max; i++)
  3209.             {
  3210.             int len = 1;
  3211.             if (eptr >= md->end_subject) break;
  3212.             GETCHARLEN(c, eptr, len);
  3213.             prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);
  3214.             if ((prop_category == prop_value) == prop_fail_result)
  3215.               break;
  3216.             eptr+= len;
  3217.             }
  3218.           break;
  3219.  
  3220.           case PT_PC:
  3221.           for (i = min; i < max; i++)
  3222.             {
  3223.             int len = 1;
  3224.             if (eptr >= md->end_subject) break;
  3225.             GETCHARLEN(c, eptr, len);
  3226.             prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);
  3227.             if ((prop_chartype == prop_value) == prop_fail_result)
  3228.               break;
  3229.             eptr+= len;
  3230.             }
  3231.           break;
  3232.  
  3233.           case PT_SC:
  3234.           for (i = min; i < max; i++)
  3235.             {
  3236.             int len = 1;
  3237.             if (eptr >= md->end_subject) break;
  3238.             GETCHARLEN(c, eptr, len);
  3239.             prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);
  3240.             if ((prop_script == prop_value) == prop_fail_result)
  3241.               break;
  3242.             eptr+= len;
  3243.             }
  3244.           break;
  3245.           }
  3246.  
  3247.         /* eptr is now past the end of the maximum run */
  3248.  
  3249.         if (possessive) continue;
  3250.         for(;;)
  3251.           {
  3252.           RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
  3253.           if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  3254.           if (eptr-- == pp) break;        /* Stop if tried at original pos */
  3255.           BACKCHAR(eptr);
  3256.           }
  3257.         }
  3258.  
  3259.       /* Match extended Unicode sequences. We will get here only if the
  3260.       support is in the binary; otherwise a compile-time error occurs. */
  3261.  
  3262.       else if (ctype == OP_EXTUNI)
  3263.         {
  3264.         for (i = min; i < max; i++)
  3265.           {
  3266.           if (eptr >= md->end_subject) break;
  3267.           GETCHARINCTEST(c, eptr);
  3268.           prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);
  3269.           if (prop_category == ucp_M) break;
  3270.           while (eptr < md->end_subject)
  3271.             {
  3272.             int len = 1;
  3273.             if (!utf8) c = *eptr; else
  3274.               {
  3275.               GETCHARLEN(c, eptr, len);
  3276.               }
  3277.             prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);
  3278.             if (prop_category != ucp_M) break;
  3279.             eptr += len;
  3280.             }
  3281.           }
  3282.  
  3283.         /* eptr is now past the end of the maximum run */
  3284.  
  3285.         if (possessive) continue;
  3286.         for(;;)
  3287.           {
  3288.           RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
  3289.           if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  3290.           if (eptr-- == pp) break;        /* Stop if tried at original pos */
  3291.           for (;;)                        /* Move back over one extended */
  3292.             {
  3293.             int len = 1;
  3294.             BACKCHAR(eptr);
  3295.             if (!utf8) c = *eptr; else
  3296.               {
  3297.               GETCHARLEN(c, eptr, len);
  3298.               }
  3299.             prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);
  3300.             if (prop_category != ucp_M) break;
  3301.             eptr--;
  3302.             }
  3303.           }
  3304.         }
  3305.  
  3306.       else
  3307. #endif   /* SUPPORT_UCP */
  3308.  
  3309. #ifdef SUPPORT_UTF8
  3310.       /* UTF-8 mode */
  3311.  
  3312.       if (utf8)
  3313.         {
  3314.         switch(ctype)
  3315.           {
  3316.           case OP_ANY:
  3317.  
  3318.           /* Special code is required for UTF8, but when the maximum is
  3319.           unlimited we don't need it, so we repeat the non-UTF8 code. This is
  3320.           probably worth it, because .* is quite a common idiom. */
  3321.  
  3322.           if (max < INT_MAX)
  3323.             {
  3324.             if ((ims & PCRE_DOTALL) == 0)
  3325.               {
  3326.               for (i = min; i < max; i++)
  3327.                 {
  3328.                 if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;
  3329.                 eptr++;
  3330.                 while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
  3331.                 }
  3332.               }
  3333.             else
  3334.               {
  3335.               for (i = min; i < max; i++)
  3336.                 {
  3337.                 if (eptr >= md->end_subject) break;
  3338.                 eptr++;
  3339.                 while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
  3340.                 }
  3341.               }
  3342.             }
  3343.  
  3344.           /* Handle unlimited UTF-8 repeat */
  3345.  
  3346.           else
  3347.             {
  3348.             if ((ims & PCRE_DOTALL) == 0)
  3349.               {
  3350.               for (i = min; i < max; i++)
  3351.                 {
  3352.                 if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;
  3353.                 eptr++;
  3354.                 }
  3355.               break;
  3356.               }
  3357.             else
  3358.               {
  3359.               c = max - min;
  3360.               if (c > (unsigned int)(md->end_subject - eptr))
  3361.                 c = md->end_subject - eptr;
  3362.               eptr += c;
  3363.               }
  3364.             }
  3365.           break;
  3366.  
  3367.           /* The byte case is the same as non-UTF8 */
  3368.  
  3369.           case OP_ANYBYTE:
  3370.           c = max - min;
  3371.           if (c > (unsigned int)(md->end_subject - eptr))
  3372.             c = md->end_subject - eptr;
  3373.           eptr += c;
  3374.           break;
  3375.  
  3376.           case OP_ANYNL:
  3377.           for (i = min; i < max; i++)
  3378.             {
  3379.             int len = 1;
  3380.             if (eptr >= md->end_subject) break;
  3381.             GETCHARLEN(c, eptr, len);
  3382.             if (c == 0x000d)
  3383.               {
  3384.               if (++eptr >= md->end_subject) break;
  3385.               if (*eptr == 0x000a) eptr++;
  3386.               }
  3387.             else
  3388.               {
  3389.               if (c != 0x000a && c != 0x000b && c != 0x000c &&
  3390.                   c != 0x0085 && c != 0x2028 && c != 0x2029)
  3391.                 break;
  3392.               eptr += len;
  3393.               }
  3394.             }
  3395.           break;
  3396.  
  3397.           case OP_NOT_DIGIT:
  3398.           for (i = min; i < max; i++)
  3399.             {
  3400.             int len = 1;
  3401.             if (eptr >= md->end_subject) break;
  3402.             GETCHARLEN(c, eptr, len);
  3403.             if (c < 256 && (md->ctypes[c] & ctype_digit) != 0) break;
  3404.             eptr+= len;
  3405.             }
  3406.           break;
  3407.  
  3408.           case OP_DIGIT:
  3409.           for (i = min; i < max; i++)
  3410.             {
  3411.             int len = 1;
  3412.             if (eptr >= md->end_subject) break;
  3413.             GETCHARLEN(c, eptr, len);
  3414.             if (c >= 256 ||(md->ctypes[c] & ctype_digit) == 0) break;
  3415.             eptr+= len;
  3416.             }
  3417.           break;
  3418.  
  3419.           case OP_NOT_WHITESPACE:
  3420.           for (i = min; i < max; i++)
  3421.             {
  3422.             int len = 1;
  3423.             if (eptr >= md->end_subject) break;
  3424.             GETCHARLEN(c, eptr, len);
  3425.             if (c < 256 && (md->ctypes[c] & ctype_space) != 0) break;
  3426.             eptr+= len;
  3427.             }
  3428.           break;
  3429.  
  3430.           case OP_WHITESPACE:
  3431.           for (i = min; i < max; i++)
  3432.             {
  3433.             int len = 1;
  3434.             if (eptr >= md->end_subject) break;
  3435.             GETCHARLEN(c, eptr, len);
  3436.             if (c >= 256 ||(md->ctypes[c] & ctype_space) == 0) break;
  3437.             eptr+= len;
  3438.             }
  3439.           break;
  3440.  
  3441.           case OP_NOT_WORDCHAR:
  3442.           for (i = min; i < max; i++)
  3443.             {
  3444.             int len = 1;
  3445.             if (eptr >= md->end_subject) break;
  3446.             GETCHARLEN(c, eptr, len);
  3447.             if (c < 256 && (md->ctypes[c] & ctype_word) != 0) break;
  3448.             eptr+= len;
  3449.             }
  3450.           break;
  3451.  
  3452.           case OP_WORDCHAR:
  3453.           for (i = min; i < max; i++)
  3454.             {
  3455.             int len = 1;
  3456.             if (eptr >= md->end_subject) break;
  3457.             GETCHARLEN(c, eptr, len);
  3458.             if (c >= 256 || (md->ctypes[c] & ctype_word) == 0) break;
  3459.             eptr+= len;
  3460.             }
  3461.           break;
  3462.  
  3463.           default:
  3464.           RRETURN(PCRE_ERROR_INTERNAL);
  3465.           }
  3466.  
  3467.         /* eptr is now past the end of the maximum run */
  3468.  
  3469.         if (possessive) continue;
  3470.         for(;;)
  3471.           {
  3472.           RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
  3473.           if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  3474.           if (eptr-- == pp) break;        /* Stop if tried at original pos */
  3475.           BACKCHAR(eptr);
  3476.           }
  3477.         }
  3478.       else
  3479. #endif
  3480.  
  3481.       /* Not UTF-8 mode */
  3482.         {
  3483.         switch(ctype)
  3484.           {
  3485.           case OP_ANY:
  3486.           if ((ims & PCRE_DOTALL) == 0)
  3487.             {
  3488.             for (i = min; i < max; i++)
  3489.               {
  3490.               if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;
  3491.               eptr++;
  3492.               }
  3493.             break;
  3494.             }
  3495.           /* For DOTALL case, fall through and treat as \C */
  3496.  
  3497.           case OP_ANYBYTE:
  3498.           c = max - min;
  3499.           if (c > (unsigned int)(md->end_subject - eptr))
  3500.             c = md->end_subject - eptr;
  3501.           eptr += c;
  3502.           break;
  3503.  
  3504.           case OP_ANYNL:
  3505.           for (i = min; i < max; i++)
  3506.             {
  3507.             if (eptr >= md->end_subject) break;
  3508.             c = *eptr;
  3509.             if (c == 0x000d)
  3510.               {
  3511.               if (++eptr >= md->end_subject) break;
  3512.               if (*eptr == 0x000a) eptr++;
  3513.               }
  3514.             else
  3515.               {
  3516.               if (c != 0x000a && c != 0x000b && c != 0x000c && c != 0x0085)
  3517.                 break;
  3518.               eptr++;
  3519.               }
  3520.             }
  3521.           break;
  3522.  
  3523.           case OP_NOT_DIGIT:
  3524.           for (i = min; i < max; i++)
  3525.             {
  3526.             if (eptr >= md->end_subject || (md->ctypes[*eptr] & ctype_digit) != 0)
  3527.               break;
  3528.             eptr++;
  3529.             }
  3530.           break;
  3531.  
  3532.           case OP_DIGIT:
  3533.           for (i = min; i < max; i++)
  3534.             {
  3535.             if (eptr >= md->end_subject || (md->ctypes[*eptr] & ctype_digit) == 0)
  3536.               break;
  3537.             eptr++;
  3538.             }
  3539.           break;
  3540.  
  3541.           case OP_NOT_WHITESPACE:
  3542.           for (i = min; i < max; i++)
  3543.             {
  3544.             if (eptr >= md->end_subject || (md->ctypes[*eptr] & ctype_space) != 0)
  3545.               break;
  3546.             eptr++;
  3547.             }
  3548.           break;
  3549.  
  3550.           case OP_WHITESPACE:
  3551.           for (i = min; i < max; i++)
  3552.             {
  3553.             if (eptr >= md->end_subject || (md->ctypes[*eptr] & ctype_space) == 0)
  3554.               break;
  3555.             eptr++;
  3556.             }
  3557.           break;
  3558.  
  3559.           case OP_NOT_WORDCHAR:
  3560.           for (i = min; i < max; i++)
  3561.             {
  3562.             if (eptr >= md->end_subject || (md->ctypes[*eptr] & ctype_word) != 0)
  3563.               break;
  3564.             eptr++;
  3565.             }
  3566.           break;
  3567.  
  3568.           case OP_WORDCHAR:
  3569.           for (i = min; i < max; i++)
  3570.             {
  3571.             if (eptr >= md->end_subject || (md->ctypes[*eptr] & ctype_word) == 0)
  3572.               break;
  3573.             eptr++;
  3574.             }
  3575.           break;
  3576.  
  3577.           default:
  3578.           RRETURN(PCRE_ERROR_INTERNAL);
  3579.           }
  3580.  
  3581.         /* eptr is now past the end of the maximum run */
  3582.  
  3583.         if (possessive) continue;
  3584.         while (eptr >= pp)
  3585.           {
  3586.           RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
  3587.           eptr--;
  3588.           if (rrc != MATCH_NOMATCH) RRETURN(rrc);
  3589.           }
  3590.         }
  3591.  
  3592.       /* Get here if we can't make it match with any permitted repetitions */
  3593.  
  3594.       RRETURN(MATCH_NOMATCH);
  3595.       }
  3596.     /* Control never gets here */
  3597.  
  3598.     /* There's been some horrible disaster. Arrival here can only mean there is
  3599.     something seriously wrong in the code above or the OP_xxx definitions. */
  3600.  
  3601.     default:
  3602.     DPRINTF(("Unknown opcode %d\n", *ecode));
  3603.     RRETURN(PCRE_ERROR_UNKNOWN_OPCODE);
  3604.     }
  3605.  
  3606.   /* Do not stick any code in here without much thought; it is assumed
  3607.   that "continue" in the code above comes out to here to repeat the main
  3608.   loop. */
  3609.  
  3610.   }             /* End of main loop */
  3611. /* Control never reaches here */
  3612. }
  3613.  
  3614.  
  3615. /***************************************************************************
  3616. ****************************************************************************
  3617.                    RECURSION IN THE match() FUNCTION
  3618.  
  3619. Undefine all the macros that were defined above to handle this. */
  3620.  
  3621. #ifdef NO_RECURSE
  3622. #undef eptr
  3623. #undef ecode
  3624. #undef offset_top
  3625. #undef ims
  3626. #undef eptrb
  3627. #undef flags
  3628.  
  3629. #undef callpat
  3630. #undef charptr
  3631. #undef data
  3632. #undef next
  3633. #undef pp
  3634. #undef prev
  3635. #undef saved_eptr
  3636.  
  3637. #undef new_recursive
  3638.  
  3639. #undef cur_is_word
  3640. #undef condition
  3641. #undef prev_is_word
  3642.  
  3643. #undef original_ims
  3644.  
  3645. #undef ctype
  3646. #undef length
  3647. #undef max
  3648. #undef min
  3649. #undef number
  3650. #undef offset
  3651. #undef op
  3652. #undef save_capture_last
  3653. #undef save_offset1
  3654. #undef save_offset2
  3655. #undef save_offset3
  3656. #undef stacksave
  3657.  
  3658. #undef newptrb
  3659.  
  3660. #endif
  3661.  
  3662. /* These two are defined as macros in both cases */
  3663.  
  3664. #undef fc
  3665. #undef fi
  3666.  
  3667. /***************************************************************************
  3668. ***************************************************************************/
  3669.  
  3670.  
  3671.  
  3672. /*************************************************
  3673. *         Execute a Regular Expression           *
  3674. *************************************************/
  3675.  
  3676. /* This function applies a compiled re to a subject string and picks out
  3677. portions of the string if it matches. Two elements in the vector are set for
  3678. each substring: the offsets to the start and end of the substring.
  3679.  
  3680. Arguments:
  3681.   argument_re     points to the compiled expression
  3682.   extra_data      points to extra data or is NULL
  3683.   subject         points to the subject string
  3684.   length          length of subject string (may contain binary zeros)
  3685.   start_offset    where to start in the subject string
  3686.   options         option bits
  3687.   offsets         points to a vector of ints to be filled in with offsets
  3688.   offsetcount     the number of elements in the vector
  3689.  
  3690. Returns:          > 0 => success; value is the number of elements filled in
  3691.                   = 0 => success, but offsets is not big enough
  3692.                    -1 => failed to match
  3693.                  < -1 => some kind of unexpected problem
  3694. */
  3695.  
  3696. PCRE_DATA_SCOPE int
  3697. pcre_exec(const pcre *argument_re, const pcre_extra *extra_data,
  3698.   PCRE_SPTR subject, int length, int start_offset, int options, int *offsets,
  3699.   int offsetcount)
  3700. {
  3701. int rc, resetcount, ocount;
  3702. int first_byte = -1;
  3703. int req_byte = -1;
  3704. int req_byte2 = -1;
  3705. int newline;
  3706. unsigned long int ims;
  3707. BOOL using_temporary_offsets = FALSE;
  3708. BOOL anchored;
  3709. BOOL startline;
  3710. BOOL firstline;
  3711. BOOL first_byte_caseless = FALSE;
  3712. BOOL req_byte_caseless = FALSE;
  3713. #ifdef SUPPORT_UTF8 /* AutoHotkey: This helps detected unintended usages of utf8. */
  3714.     BOOL utf8;
  3715. #endif /* AutoHotkey. */
  3716. match_data match_block;
  3717. match_data *md = &match_block;
  3718. const uschar *tables;
  3719. const uschar *start_bits = NULL;
  3720. USPTR start_match = (USPTR)subject + start_offset;
  3721. USPTR end_subject;
  3722. USPTR req_byte_ptr = start_match - 1;
  3723. eptrblock eptrchain[EPTR_WORK_SIZE];
  3724.  
  3725. pcre_study_data internal_study;
  3726. const pcre_study_data *study;
  3727.  
  3728. real_pcre internal_re;
  3729. const real_pcre *external_re = (const real_pcre *)argument_re;
  3730. const real_pcre *re = external_re;
  3731.  
  3732. /* Plausibility checks */
  3733.  
  3734. if ((options & ~PUBLIC_EXEC_OPTIONS) != 0) return PCRE_ERROR_BADOPTION;
  3735. if (re == NULL || subject == NULL ||
  3736.    (offsets == NULL && offsetcount > 0)) return PCRE_ERROR_NULL;
  3737. if (offsetcount < 0) return PCRE_ERROR_BADCOUNT;
  3738.  
  3739. /* Fish out the optional data from the extra_data structure, first setting
  3740. the default values. */
  3741.  
  3742. study = NULL;
  3743. md->match_limit = MATCH_LIMIT;
  3744. md->match_limit_recursion = MATCH_LIMIT_RECURSION;
  3745. md->callout_data = NULL;
  3746.  
  3747. /* The table pointer is always in native byte order. */
  3748.  
  3749. tables = external_re->tables;
  3750.  
  3751. if (extra_data != NULL)
  3752.   {
  3753.   register unsigned int flags = extra_data->flags;
  3754.   if ((flags & PCRE_EXTRA_STUDY_DATA) != 0)
  3755.     study = (const pcre_study_data *)extra_data->study_data;
  3756.   if ((flags & PCRE_EXTRA_MATCH_LIMIT) != 0)
  3757.     md->match_limit = extra_data->match_limit;
  3758.   if ((flags & PCRE_EXTRA_MATCH_LIMIT_RECURSION) != 0)
  3759.     md->match_limit_recursion = extra_data->match_limit_recursion;
  3760.   if ((flags & PCRE_EXTRA_CALLOUT_DATA) != 0)
  3761.     md->callout_data = extra_data->callout_data;
  3762.   if ((flags & PCRE_EXTRA_TABLES) != 0) tables = extra_data->tables;
  3763.   }
  3764.  
  3765. /* If the exec call supplied NULL for tables, use the inbuilt ones. This
  3766. is a feature that makes it possible to save compiled regex and re-use them
  3767. in other programs later. */
  3768.  
  3769. if (tables == NULL) tables = _pcre_default_tables;
  3770.  
  3771. /* Check that the first field in the block is the magic number. If it is not,
  3772. test for a regex that was compiled on a host of opposite endianness. If this is
  3773. the case, flipped values are put in internal_re and internal_study if there was
  3774. study data too. */
  3775.  
  3776. if (re->magic_number != MAGIC_NUMBER)
  3777.   {
  3778.   re = _pcre_try_flipped(re, &internal_re, study, &internal_study);
  3779.   if (re == NULL) return PCRE_ERROR_BADMAGIC;
  3780.   if (study != NULL) study = &internal_study;
  3781.   }
  3782.  
  3783. /* Set up other data */
  3784.  
  3785. anchored = ((re->options | options) & PCRE_ANCHORED) != 0;
  3786. startline = (re->options & PCRE_STARTLINE) != 0;
  3787. firstline = (re->options & PCRE_FIRSTLINE) != 0;
  3788.  
  3789. /* The code starts after the real_pcre block and the capture name table. */
  3790.  
  3791. md->start_code = (const uschar *)external_re + re->name_table_offset +
  3792.   re->name_count * re->name_entry_size;
  3793.  
  3794. md->start_subject = (USPTR)subject;
  3795. md->start_offset = start_offset;
  3796. md->end_subject = md->start_subject + length;
  3797. end_subject = md->end_subject;
  3798.  
  3799. md->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0;
  3800. #ifdef SUPPORT_UTF8 /* AutoHotkey. */
  3801.     utf8 = md->utf8 = (re->options & PCRE_UTF8) != 0;
  3802. #endif /* AutoHotkey. */
  3803.  
  3804. md->notbol = (options & PCRE_NOTBOL) != 0;
  3805. md->noteol = (options & PCRE_NOTEOL) != 0;
  3806. md->notempty = (options & PCRE_NOTEMPTY) != 0;
  3807. md->partial = (options & PCRE_PARTIAL) != 0;
  3808. md->hitend = FALSE;
  3809.  
  3810. md->recursive = NULL;                   /* No recursion at top level */
  3811. md->eptrchain = eptrchain;              /* Make workspace generally available */
  3812.  
  3813. md->lcc = tables + lcc_offset;
  3814. md->ctypes = tables + ctypes_offset;
  3815.  
  3816. /* Handle different types of newline. The two bits give four cases. If nothing
  3817. is set at run time, whatever was used at compile time applies. */
  3818.  
  3819. switch ((((options & PCRE_NEWLINE_BITS) == 0)? re->options : options) &
  3820.        PCRE_NEWLINE_BITS)
  3821.   {
  3822.   case 0: newline = NEWLINE; break;   /* Compile-time default */
  3823.   case PCRE_NEWLINE_CR: newline = '\r'; break;
  3824.   case PCRE_NEWLINE_LF: newline = '\n'; break;
  3825.   case PCRE_NEWLINE_CR+
  3826.        PCRE_NEWLINE_LF: newline = ('\r' << 8) | '\n'; break;
  3827.   case PCRE_NEWLINE_ANY: newline = -1; break;
  3828.   default: return PCRE_ERROR_BADNEWLINE;
  3829.   }
  3830.  
  3831. if (newline < 0)
  3832.   {
  3833.   md->nltype = NLTYPE_ANY;
  3834.   }
  3835. else
  3836.   {
  3837.   md->nltype = NLTYPE_FIXED;
  3838.   if (newline > 255)
  3839.     {
  3840.     md->nllen = 2;
  3841.     md->nl[0] = (newline >> 8) & 255;
  3842.     md->nl[1] = newline & 255;
  3843.     }
  3844.   else
  3845.     {
  3846.     md->nllen = 1;
  3847.     md->nl[0] = newline;
  3848.     }
  3849.   }
  3850.  
  3851. /* Partial matching is supported only for a restricted set of regexes at the
  3852. moment. */
  3853.  
  3854. if (md->partial && (re->options & PCRE_NOPARTIAL) != 0)
  3855.   return PCRE_ERROR_BADPARTIAL;
  3856.  
  3857. /* Check a UTF-8 string if required. Unfortunately there's no way of passing
  3858. back the character offset. */
  3859.  
  3860. #ifdef SUPPORT_UTF8
  3861. if (utf8 && (options & PCRE_NO_UTF8_CHECK) == 0)
  3862.   {
  3863.   if (_pcre_valid_utf8((uschar *)subject, length) >= 0)
  3864.     return PCRE_ERROR_BADUTF8;
  3865.   if (start_offset > 0 && start_offset < length)
  3866.     {
  3867.     int tb = ((uschar *)subject)[start_offset];
  3868.     if (tb > 127)
  3869.       {
  3870.       tb &= 0xc0;
  3871.       if (tb != 0 && tb != 0xc0) return PCRE_ERROR_BADUTF8_OFFSET;
  3872.       }
  3873.     }
  3874.   }
  3875. #endif
  3876.  
  3877. /* The ims options can vary during the matching as a result of the presence
  3878. of (?ims) items in the pattern. They are kept in a local variable so that
  3879. restoring at the exit of a group is easy. */
  3880.  
  3881. ims = re->options & (PCRE_CASELESS|PCRE_MULTILINE|PCRE_DOTALL);
  3882.  
  3883. /* If the expression has got more back references than the offsets supplied can
  3884. hold, we get a temporary chunk of working store to use during the matching.
  3885. Otherwise, we can use the vector supplied, rounding down its size to a multiple
  3886. of 3. */
  3887.  
  3888. ocount = offsetcount - (offsetcount % 3);
  3889.  
  3890. if (re->top_backref > 0 && re->top_backref >= ocount/3)
  3891.   {
  3892.   ocount = re->top_backref * 3 + 3;
  3893.   md->offset_vector = (int *)(pcre_malloc)(ocount * sizeof(int));
  3894.   if (md->offset_vector == NULL) return PCRE_ERROR_NOMEMORY;
  3895.   using_temporary_offsets = TRUE;
  3896.   DPRINTF(("Got memory to hold back references\n"));
  3897.   }
  3898. else md->offset_vector = offsets;
  3899.  
  3900. md->offset_end = ocount;
  3901. md->offset_max = (2*ocount)/3;
  3902. md->offset_overflow = FALSE;
  3903. md->capture_last = -1;
  3904.  
  3905. /* Compute the minimum number of offsets that we need to reset each time. Doing
  3906. this makes a huge difference to execution time when there aren't many brackets
  3907. in the pattern. */
  3908.  
  3909. resetcount = 2 + re->top_bracket * 2;
  3910. if (resetcount > offsetcount) resetcount = ocount;
  3911.  
  3912. /* Reset the working variable associated with each extraction. These should
  3913. never be used unless previously set, but they get saved and restored, and so we
  3914. initialize them to avoid reading uninitialized locations. */
  3915.  
  3916. if (md->offset_vector != NULL)
  3917.   {
  3918.   register int *iptr = md->offset_vector + ocount;
  3919.   register int *iend = iptr - resetcount/2 + 1;
  3920.   while (--iptr >= iend) *iptr = -1;
  3921.   }
  3922.  
  3923. /* Set up the first character to match, if available. The first_byte value is
  3924. never set for an anchored regular expression, but the anchoring may be forced
  3925. at run time, so we have to test for anchoring. The first char may be unset for
  3926. an unanchored pattern, of course. If there's no first char and the pattern was
  3927. studied, there may be a bitmap of possible first characters. */
  3928.  
  3929. if (!anchored)
  3930.   {
  3931.   if ((re->options & PCRE_FIRSTSET) != 0)
  3932.     {
  3933.     first_byte = re->first_byte & 255;
  3934.     if ((first_byte_caseless = ((re->first_byte & REQ_CASELESS) != 0)) == TRUE)
  3935.       first_byte = md->lcc[first_byte];
  3936.     }
  3937.   else
  3938.     if (!startline && study != NULL &&
  3939.       (study->options & PCRE_STUDY_MAPPED) != 0)
  3940.         start_bits = study->start_bits;
  3941.   }
  3942.  
  3943. /* For anchored or unanchored matches, there may be a "last known required
  3944. character" set. */
  3945.  
  3946. if ((re->options & PCRE_REQCHSET) != 0)
  3947.   {
  3948.   req_byte = re->req_byte & 255;
  3949.   req_byte_caseless = (re->req_byte & REQ_CASELESS) != 0;
  3950.   req_byte2 = (tables + fcc_offset)[req_byte];  /* case flipped */
  3951.   }
  3952.  
  3953.  
  3954. /* ==========================================================================*/
  3955.  
  3956. /* Loop for handling unanchored repeated matching attempts; for anchored regexs
  3957. the loop runs just once. */
  3958.  
  3959. for(;;)
  3960.   {
  3961.   USPTR save_end_subject = end_subject;
  3962.  
  3963.   /* Reset the maximum number of extractions we might see. */
  3964.  
  3965.   if (md->offset_vector != NULL)
  3966.     {
  3967.     register int *iptr = md->offset_vector;
  3968.     register int *iend = iptr + resetcount;
  3969.     while (iptr < iend) *iptr++ = -1;
  3970.     }
  3971.  
  3972.   /* Advance to a unique first char if possible. If firstline is TRUE, the
  3973.   start of the match is constrained to the first line of a multiline string.
  3974.   That is, the match must be before or at the first newline. Implement this by
  3975.   temporarily adjusting end_subject so that we stop scanning at a newline. If
  3976.   the match fails at the newline, later code breaks this loop. */
  3977.  
  3978.   if (firstline)
  3979.     {
  3980.     USPTR t = start_match;
  3981.     while (t < md->end_subject && !IS_NEWLINE(t)) t++;
  3982.     end_subject = t;
  3983.     }
  3984.  
  3985.   /* Now test for a unique first byte */
  3986.  
  3987.   if (first_byte >= 0)
  3988.     {
  3989.     if (first_byte_caseless)
  3990.       while (start_match < end_subject &&
  3991.              md->lcc[*start_match] != first_byte)
  3992.         start_match++;
  3993.     else
  3994.       while (start_match < end_subject && *start_match != first_byte)
  3995.         start_match++;
  3996.     }
  3997.  
  3998.   /* Or to just after a linebreak for a multiline match if possible */
  3999.  
  4000.   else if (startline)
  4001.     {
  4002.     if (start_match > md->start_subject + start_offset)
  4003.       {
  4004.       while (start_match <= end_subject && !WAS_NEWLINE(start_match))
  4005.         start_match++;
  4006.       }
  4007.     }
  4008.  
  4009.   /* Or to a non-unique first char after study */
  4010.  
  4011.   else if (start_bits != NULL)
  4012.     {
  4013.     while (start_match < end_subject)
  4014.       {
  4015.       register unsigned int c = *start_match;
  4016.       if ((start_bits[c/8] & (1 << (c&7))) == 0) start_match++; else break;
  4017.       }
  4018.     }
  4019.  
  4020.   /* Restore fudged end_subject */
  4021.  
  4022.   end_subject = save_end_subject;
  4023.  
  4024. #ifdef DEBUG  /* Sigh. Some compilers never learn. */
  4025.   printf(">>>> Match against: ");
  4026.   pchars(start_match, end_subject - start_match, TRUE, md);
  4027.   printf("\n");
  4028. #endif
  4029.  
  4030.   /* If req_byte is set, we know that that character must appear in the subject
  4031.   for the match to succeed. If the first character is set, req_byte must be
  4032.   later in the subject; otherwise the test starts at the match point. This
  4033.   optimization can save a huge amount of backtracking in patterns with nested
  4034.   unlimited repeats that aren't going to match. Writing separate code for
  4035.   cased/caseless versions makes it go faster, as does using an autoincrement
  4036.   and backing off on a match.
  4037.  
  4038.   HOWEVER: when the subject string is very, very long, searching to its end can
  4039.   take a long time, and give bad performance on quite ordinary patterns. This
  4040.   showed up when somebody was matching something like /^\d+C/ on a 32-megabyte
  4041.   string... so we don't do this when the string is sufficiently long.
  4042.  
  4043.   ALSO: this processing is disabled when partial matching is requested.
  4044.   */
  4045.  
  4046.   if (req_byte >= 0 &&
  4047.       end_subject - start_match < REQ_BYTE_MAX &&
  4048.       !md->partial)
  4049.     {
  4050.     register USPTR p = start_match + ((first_byte >= 0)? 1 : 0);
  4051.  
  4052.     /* We don't need to repeat the search if we haven't yet reached the
  4053.     place we found it at last time. */
  4054.  
  4055.     if (p > req_byte_ptr)
  4056.       {
  4057.       if (req_byte_caseless)
  4058.         {
  4059.         while (p < end_subject)
  4060.           {
  4061.           register int pp = *p++;
  4062.           if (pp == req_byte || pp == req_byte2) { p--; break; }
  4063.           }
  4064.         }
  4065.       else
  4066.         {
  4067.         while (p < end_subject)
  4068.           {
  4069.           if (*p++ == req_byte) { p--; break; }
  4070.           }
  4071.         }
  4072.  
  4073.       /* If we can't find the required character, break the matching loop,
  4074.       forcing a match failure. */
  4075.  
  4076.       if (p >= end_subject)
  4077.         {
  4078.         rc = MATCH_NOMATCH;
  4079.         break;
  4080.         }
  4081.  
  4082.       /* If we have found the required character, save the point where we
  4083.       found it, so that we don't search again next time round the loop if
  4084.       the start hasn't passed this character yet. */
  4085.  
  4086.       req_byte_ptr = p;
  4087.       }
  4088.     }
  4089.  
  4090.   /* OK, we can now run the match. */
  4091.  
  4092.   md->start_match = start_match;
  4093.   md->match_call_count = 0;
  4094.   md->eptrn = 0;                          /* Next free eptrchain slot */
  4095.   rc = match(start_match, md->start_code, 2, md, ims, NULL, 0, 0);
  4096.  
  4097.   /* Any return other than MATCH_NOMATCH breaks the loop. */
  4098.  
  4099.   if (rc != MATCH_NOMATCH) break;
  4100.  
  4101.   /* If PCRE_FIRSTLINE is set, the match must happen before or at the first
  4102.   newline in the subject (though it may continue over the newline). Therefore,
  4103.   if we have just failed to match, starting at a newline, do not continue. */
  4104.  
  4105.   if (firstline && IS_NEWLINE(start_match)) break;
  4106.  
  4107.   /* Advance the match position by one character. */
  4108.  
  4109.   start_match++;
  4110. #ifdef SUPPORT_UTF8
  4111.   if (utf8)
  4112.     while(start_match < end_subject && (*start_match & 0xc0) == 0x80)
  4113.       start_match++;
  4114. #endif
  4115.  
  4116.   /* Break the loop if the pattern is anchored or if we have passed the end of
  4117.   the subject. */
  4118.  
  4119.   if (anchored || start_match > end_subject) break;
  4120.  
  4121.   /* If we have just passed a CR and the newline option is CRLF or ANY, and we
  4122.   are now at a LF, advance the match position by one more character. */
  4123.  
  4124.   if (start_match[-1] == '\r' &&
  4125.        (md->nltype == NLTYPE_ANY || md->nllen == 2) &&
  4126.        start_match < end_subject &&
  4127.        *start_match == '\n')
  4128.     start_match++;
  4129.  
  4130.   }   /* End of for(;;) "bumpalong" loop */
  4131.  
  4132. /* ==========================================================================*/
  4133.  
  4134. /* We reach here when rc is not MATCH_NOMATCH, or if one of the stopping
  4135. conditions is true:
  4136.  
  4137. (1) The pattern is anchored;
  4138.  
  4139. (2) We are past the end of the subject;
  4140.  
  4141. (3) PCRE_FIRSTLINE is set and we have failed to match at a newline, because
  4142.     this option requests that a match occur at or before the first newline in
  4143.     the subject.
  4144.  
  4145. When we have a match and the offset vector is big enough to deal with any
  4146. backreferences, captured substring offsets will already be set up. In the case
  4147. where we had to get some local store to hold offsets for backreference
  4148. processing, copy those that we can. In this case there need not be overflow if
  4149. certain parts of the pattern were not used, even though there are more
  4150. capturing parentheses than vector slots. */
  4151.  
  4152. if (rc == MATCH_MATCH)
  4153.   {
  4154.   if (using_temporary_offsets)
  4155.     {
  4156.     if (offsetcount >= 4)
  4157.       {
  4158.       memcpy(offsets + 2, md->offset_vector + 2,
  4159.         (offsetcount - 2) * sizeof(int));
  4160.       DPRINTF(("Copied offsets from temporary memory\n"));
  4161.       }
  4162.     if (md->end_offset_top > offsetcount) md->offset_overflow = TRUE;
  4163.     DPRINTF(("Freeing temporary memory\n"));
  4164.     (pcre_free)(md->offset_vector);
  4165.     }
  4166.  
  4167.   /* Set the return code to the number of captured strings, or 0 if there are
  4168.   too many to fit into the vector. */
  4169.  
  4170.   rc = md->offset_overflow? 0 : md->end_offset_top/2;
  4171.  
  4172.   /* If there is space, set up the whole thing as substring 0. */
  4173.  
  4174.   if (offsetcount < 2) rc = 0; else
  4175.     {
  4176.     offsets[0] = start_match - md->start_subject;
  4177.     offsets[1] = md->end_match_ptr - md->start_subject;
  4178.     }
  4179.  
  4180.   DPRINTF((">>>> returning %d\n", rc));
  4181.   return rc;
  4182.   }
  4183.  
  4184. /* Control gets here if there has been an error, or if the overall match
  4185. attempt has failed at all permitted starting positions. */
  4186.  
  4187. if (using_temporary_offsets)
  4188.   {
  4189.   DPRINTF(("Freeing temporary memory\n"));
  4190.   (pcre_free)(md->offset_vector);
  4191.   }
  4192.  
  4193. if (rc != MATCH_NOMATCH)
  4194.   {
  4195.   DPRINTF((">>>> error: returning %d\n", rc));
  4196.   return rc;
  4197.   }
  4198. else if (md->partial && md->hitend)
  4199.   {
  4200.   DPRINTF((">>>> returning PCRE_ERROR_PARTIAL\n"));
  4201.   return PCRE_ERROR_PARTIAL;
  4202.   }
  4203. else
  4204.   {
  4205.   DPRINTF((">>>> returning PCRE_ERROR_NOMATCH\n"));
  4206.   return PCRE_ERROR_NOMATCH;
  4207.   }
  4208. }
  4209.  
  4210. /* End of pcre_exec.c */
  4211.